Problems mapping inheritance in Entity Framework

c# entity-framework

Question

I am trying to learn EF and ran into some issue. I have a database, let's simplify it, of 4 tables:

1) Items(NodeID, other fields), 
2) Nodes(NodeID, extra), 
3) Recipient(RecipientID, others) 
4) NodesRecipient(RecipientID, NodeID).

Item-Node is 1-1 relationship, primary key is NodeID Recipient has primary key RecipientID, and NodesRecipient keys are RecipientID and NodeID. Below is the diagram Node inherits from item I created an EF model from the database above using VS 2012. After the model is created, I made Node derived from Items by specifying its base as Item and deleted the 1-1 relation between them. I also made Items abstract as I do not want direct manipulation on that entity.

The compiler is complaining:

Error 1 Error 3024: Problem in mapping fragments starting at line 266:Must specify mapping for all key properties (Items.nodeID) of the EntitySet Items.

But if I did not use inheritance, the compiler would not complaint and it was fine.

No inheritance

What is my issue and how do I get around it? It would be nice if EF allows inheritance and I think it may since it allows me to specify the base class, but I think there may be some links that I might have missed when reading Microsoft documentation.

1
2
5/14/2018 6:21:48 PM

Accepted Answer

It seems like you may be missing a foreign key from the primary key of the child entity's table and the primary key of the base entity's table.

After adding the FK, update EDMX from schema (from database).

4
12/17/2013 4:14:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow