开发者

Using inheritance in Entity Framework?

开发者 https://www.devze.com 2023-01-07 04:15 出处:网络
i have two tables in DB: Foo and Bar Using Entity Framework i want to create base entity which will contain properties which both tables have.

i have two tables in DB: Foo and Bar

Using Entity Framework i want to create base entity which will contain properties which both tables have.

For example Foo has columns Id,CreateDate,FooValue and Bar has Id,CreateDate,BarValue

  • So BaseEntity should have Id and CreateDat开发者_JAVA技巧e properties
  • Foo should inherit BaseEntity and have FooValue
  • Bar should inherit BaseEntity and have BarValue

How to map properties to their tables in DB?


I assume you want Table per Concrete Type (TPC) - here is a blog post with a walkthrough. One could also think about modifing the tables and using Table per Type (TPT) but I think this would be a bad decision for columns like CreationDate because you will get one table containing the creation dates from all tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消