c# - EF Code First property with hierarchy -


while using entity framework code first 6, i'm trying replicate following model:

model design

class abstract class, implemented a1 , a2. additionally, class exposes navigation property, navigationpropertyb, class b abstract class implemented b1 , b2.

class objects can have 1 class b object , bs can participate multiple times in class instances.

currently i'm using table per hierarchy , b table per concrete type.

class hierarchy mapped correctly , following mapping being used:

    modelbuilder.entity<a>()                 .map<a1>(m => m.requires("atype").hasvalue((int)atype.a1))                 .map<a2>(m => m.requires("atype").hasvalue((int)atype.a2)) 

i understand it's similar concept i'm struggling working mapping model a's navigationpropertyb.

can help?

thank you!

you're trying create one-to-many relationship between a , b, since each b can potentially have relationship multiple as. problem here since you're using table per concrete type (tpc) inheritance b's hierarchy, won't able create single association between a , classes in hierarchy of b. here's quote linked article on tpc:

...the sql schema not aware of inheritance; effectively, we’ve mapped 2 unrelated tables more expressive class structure.... have emphasize there no relationship between database tables, except fact share similar columns.

in other words, tpc, since types not share table, possible have duplicate key values across entities within b's hierarchy!

so if want create association between a , b you'll need either

  • create separate association each concrete type in b's hierarchy
  • change inheritance mapping tph or tpt

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -