How to save derived type (TPT) in Entity Framework?

Posted by Peter Stegnar on Stack Overflow See other posts from Stack Overflow or by Peter Stegnar
Published on 2010-04-22T09:12:15Z Indexed on 2010/04/22 9:13 UTC
Read the original article Hit count: 195

Filed under:
|
|

I have problems with saving derived type (TPT) with Entity Framework to database.

Let's say I have base entity Animal and derived type Dog.

I want to save Dog entity.

I thought that I could do it like contex.AddToDogs(), but contex contain only base entity - Animal. So I can only save Animal object - contex.AddToAnimals().

I have also tried with contex.AddObject("Animals", dogInstance), but I get the following error: The member with identity 'NavigationProperty' does not exist in the metadata collection.

But I have add EntityReference to the "NavigationProperty".

So how to save derived type in EF?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about inheritance