Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: EntityFramework 5 Code First multiple inheritance mapping (Table Per Concrete Type) [1049]

$
0
0
#Steps to Reproduce#
---

##Model##

public class Gender
{
[Key]
public Guid GenderId { get; set; }

[Required]
[MaxLength(250)]
public string Name { get; set; }
}

public abstract class Person
{
[Key]
public Guid PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Gender Gender { get; set; }
}

public class Employee : Person
{
public decimal BaseSalary { get; set; }
}

public class ExecutiveEmployee : Employee
{
public string Title { get; set; }
}

#Context#

public class MyContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
public DbSet<ExecutiveEmployee> ExecutiveEmployees { get; set; }
public DbSet<Gender> Genders { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>().Map(x =>
{
x.MapInheritedProperties();
x.ToTable("Employees");
});

modelBuilder.Entity<ExecutiveEmployee>().Map(x =>
{
x.MapInheritedProperties();
x.ToTable("ExecutiveEmployees");
});
}
}

#The current result#

When I generate the database model from this entities, this is what I get:

![Image](http://i.stack.imgur.com/J2yTa.png)

As you can see, EntityFramework is actually mapping the simple properties like strings, and Guids, but it's excluding the reference properties in my inheritance hierarchy

#My expectation#

I was expecting to have two tables in my database, (Employees and ExecutiveEmployees), __both with ALL the inherited members of the parent classes, including all the inherited reference type properties not just the value type properties__

#External links#

* [I asked this question in StackOverflow](http://stackoverflow.com/q/15440485/1268570)
* [Code of this sample - Visual Studio 2012 - Console App](http://sdrv.ms/WtfcVr)

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>