EF 4.3.1 How to map a sub sub class with table per type

允我心安 提交于 2019-12-11 02:21:29

问题


I have an abstract base class called Party. There are several concrete subclasses (Company, Person, Department). Party has a property called PartyType which is use as the discriminator. Each type is in its own table with configurations like

Map<Person>(p => p.Requires("PartyType").HasValue("Person").ToTable("People");

Everything works well. Now I want to add a subclass of Person called Employee. How do I map this? I've tried

Map<Employee>(e => e.Requires("PartyType").HasValue("Employee")
   .ToTable("Employees");

but this gives a runtime error of

(43,10) : error 3032: Problem in mapping fragments starting at lines 43, 84:EntityTypes WOL.EFData.Person, WOL.EFData.Employee are being mapped to the same rows in table People. Mapping conditions can be used to distinguish the rows that these types are mapped to.


回答1:


In table per type mapping EF does not expect a discriminator configuration.

modelBuilder.Entity<Person>().ToTable("People");
modelBuilder.Entity<Employee>().ToTable("Employees");

See this article for more information.



来源:https://stackoverflow.com/questions/11148534/ef-4-3-1-how-to-map-a-sub-sub-class-with-table-per-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!