Click to See Complete Forum and Search --> : Entity Framework and Self Refrencing Entities


pnolan
March 20th, 2009, 12:24 AM
Hi,

I have a question regarding the Entity Framework that I am hoping you could answer.
Background

I have defined a model with Table-per-Type Inheritance using the EF. For the purpose of this question let’s just say I have 1 table called Tree. Tree contains 3 columns Id, Name and BranchId. Tree is a self-referencing table with a foreign key of (BranchId) REFERENCES Tree(Id).

My EF Model is bound to dbo.Views rather than dbo.Tables. Therefore, the Keys and Foreign Keys are not automatically mapped. I am hoping this is resolved in the next release of EF.

Issue
From what I am aware, EF does support self-referencing entities. However, when I validate my model I get the following exception:

Error 1 Error 2027: If an EntitySet or AssociationSet includes a function mapping, all related entity and AssociationSets in the EntityContainer must also define function mappings. The following sets require function mappings: TreeTree.

My tree entity has the relevant CUD sprocs mapped. If I remove the self referencing association the model successfully validates and everything works ok.

When I open the edmx in notepad, there is an AssociationSetMapping element for TreeTree but there is no ModificationFunctionMapping element.

Question
Could you please shed some light on what may be causing this exception? I know that the AssociationSetMapping element supports the ModificationFunctionMapping element. So is this just an issue with the designer. If this is a problem with the designer is there a hotfix I can apply?

Thanks heaps,
Patrick

JonnyPoet
March 22nd, 2009, 06:12 PM
Here I found an example maybe it helps
http://hardypickert.de/blog/PermaLink,guid,da94b670-a0f7-4180-a4ac-b965d65584ac.aspx

No idea, because never used entity framework, but simple googled for it