This is a simplified version of the problem I am trying to solve:
There are two entities:
Item
ItemID (PK)
Other simple properties...
WorkItem (navigation property)
WorkItem
ItemID (PK)
Other Simple Properties...
Item (Navigation property)
I need to create an Item, a WorkItem for it and I need to set both the navigation properties so the the two entities can point to each other, before saving.
This I can do:
Item newItem = Item.CreateItem(0, blah,blah,blah);
service.AddToItems(newItem);
WorkItem newWorkItem = new WorkItem();
service.AddToWorkItems(newWorkItem);
//set the navigation properties
newItem.WorkItem = newWorkItem;
newWorkItem.Item = newItem;
Unfortunately, when it comes to saving, this fails. I believe EF, when trying to set WorkItem's Item association, tries to set WorkItem's primary key.
Can anybody enlighten me as to the correct way to achieve this please?
Update:
So, I have tried building the model using inheritance. The model builds and validates.
Unfortunately, adding a WCF Data Service for my model and trying to view the service in a browser gives me this:
..... <m:message xml:lang="en-US">An error occurred while processing this request. </m:message>
<m:innererror>
<m:message>Navigation Properties are not supported on derived entity types. Entity Set 'app_Items' has a instance of type 'tempmodel.app_CostItem', which is an derived entity type and has navigation properties. Please remove all the navigation properties from type 'tempmodel.app_CostItem'.</m:message>
<m:type>System.InvalidOperationException</m:type>
<m:stacktrace> at System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded, ......
CostItem being another entity, like WorkItem, which derives from Item.