Bypass Inheritance RRS feed

  • Question

  • I would like to turn off Inheritance (both TPT and TPH).  For example I have the following simple DbContext

        class TptContext : DbContext
            public DbSet<DbObject> DbObjects { get; set; }
            public DbSet<Contact> Contacts { get; set; }
            public DbSet<Person> People { get; set; }

    I would like to insert into People by doing

    using (var context = new TptContext())
        context.People.Add(new Person { Id = Guid.NewGuid(), DisplayText = "This is a Person", FileAs = "Shillington, Ralph", GivenName = "Ralph", Surname = "Shillington" });

    All of the properties of the Person class map to the People View in the database. I'm using a view rather than a table because I cannot afford the performance nightmare that results when EF tries to create a query following TPT.

    For a detailed explanation of the issue with TPT see my stack overflow question:

    I believe I can get the behavior I need from EF if it will just treat each entity in my model as concrete types, and ignore the inheritance.




    Wednesday, September 28, 2011 1:40 PM

All replies

  • I think the CLR won't compile your code, the base class couldn't get the children properties. I think you should redesign your class.

    EF maping view, it always use Stored procedure to mapping the entities in EF, EF4.1 code first doesn't support SP, I'm not sure how do you handle this?

    I am fish.
    Monday, October 3, 2011 9:05 AM