Paul Linton
Paul Linton

Reputation: 150

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

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.

Upvotes: 2

Views: 1752

Answers (1)

Eranga
Eranga

Reputation: 32447

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.

Upvotes: 1

Related Questions