2

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.

naveen
  • 53,448
  • 46
  • 161
  • 251
user1205746
  • 3,110
  • 11
  • 44
  • 73

1 Answers1

4

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).

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
  • Thank you so much, Danny for being patient with me as I just played with EF the very first time this morning. After you pointed out, I noticed that NodeID in Node entity is not a key. But that field is a key in my database. Not sure why the key was not translated correctly to VS 2012. But I will attempt to reimport and see how it turn out. I believe that is something related to the inheritance though as it only complaints when I fiddled with the base type after the import was done. If I leave it as is, there was no error. Not sure what to look for anymore.. The error code is 3024 and not 3007 – user1205746 Dec 17 '13 at 16:54
  • 1
    The id should not appear on the inheriting type's entity - it should only be mapped to a property on the base type. – Danny Varod Dec 17 '13 at 17:07
  • That's it!!! I have to remove NodeID from Item!!. I did not know that! Thank you so much!! I can not tell how much I appreciate your assistance... :) – user1205746 Dec 17 '13 at 17:10