0

Database schema:

Id   int Identity NOT NULL
Name nvarchar(50) 
Discriminator nvarchar(20) NULL

Database data:

1, 'John Doe', 'Manager'
2, 'Jane Doe', 'Supervisor'

C# Entities:

public abstract class Employee 
{
    public Int32 Id {get;set;} 
    public String Name {get;set;}
} 

public class Manager : Employee { }
public class Supervisor : Employee { }

Why does the following mapping not work?

var employee = modelBuilder.Entity<Employee>();

employee.Map<Manager>(e => e.Requires("Discriminator").HasValue("Manager"));
employee.Map<Supervisor>(e => e.Requires("Discriminator").HasValue("Supervisor"));
jwize
  • 4,230
  • 1
  • 33
  • 51
  • 2
    What's the error? – Austin Brunkhorst Dec 22 '17 at 01:21
  • Strange question - *I get an error*. The only errors I get from your sample is the compile error for `modelBinder` variable (should be `modelBuilder`) and runtime error for `Employee` entity not having PK (did you miss `public int Id { get; set; }`?). Both are irrelevant to TPH. – Ivan Stoev Dec 22 '17 at 13:24
  • I did type out the example and forgot to add the Id but not in the actual code. – jwize Dec 23 '17 at 03:10

0 Answers0