开发者

EF: a separate table for each entity type in the hierarchy

开发者 https://www.devze.com 2023-03-15 07:44 出处:网络
Working with EF 4 data model, let\'s say we have a type named \"Animal\" and two other types \"Bird\" and \"Horse\" that inherit from Animal type.

Working with EF 4 data model, let's say we have a type named "Animal" and two other types "Bird" and "Horse" that inherit from Animal type.

I want the properties on type Animal to be inherited on sub types but I want those sub types to have their 开发者_JAVA技巧of separate tables, each repeating the columns inherited from Animal. Type Animal will not exist in the database. From a database perspective there will not be inheritance but having inheritance in the EF model will ease management of model.

Is is possible to define such a model/mapping in EF?


You need TPC mapping (Table per Concrete Type or Table per Class).


Yes - its called "Table per Type" and there are walkthroughs here

http://msdn.microsoft.com/en-us/library/cc716702.aspx

http://msdn.microsoft.com/en-us/library/bb738685.aspx

Edit: However, if you may also want to look at Table per Concrete Type. The various type schemes are compared here http://msdn.microsoft.com/en-us/library/cc716779.aspx

"In this mapping scenario, non-abstract types are each mapped to an individual table. Each of these tables must have columns that map to all of the properties of the derived type, including the properties inherited from the base type."

0

精彩评论

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

关注公众号