Entity Framework 4.1 Inheritance – Table per Concrete Type

There’s one more way to implement the sample domain model in the database and that’s a table for each class with all properties. And unfortunatly our luck ends a bit here. Although it’s possible to generate an ERD that looks like what we want to achieve I need to change the domain model.

You get the database model above by using the following mapping code

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        .Map(x =>  x.MapInheritedProperties())
        .Map(x => x.MapInheritedProperties())
        .Map(x=> x.MapInheritedProperties())

Pollymorphic associations though are not supported using this inheritance strategy and so you need to omit the collection of products in the category class, bummer.

public class Category
    public virtual Guid Id { get; set; }
    public virtual string Name { get; set; }
    //public virtual IList<Product> Products { get; set; }

Leave a Reply

Your email address will not be published. Required fields are marked *