Problem with displaying fragments in EF4

I have the following model:

alt text

But when I compile VS2010, I get the following error:

Error 2 Error 3007: a problem when displaying fragments starting from lines 1784, 2018: columns (created) are displayed in both fragments with different conceptual lateral properties.

What do I want? In fact, I want the Note object to have an FK for the user object. When does the error appear? When I add the user FK to the note, I have an error. If I delete the link, no problem. What is the problem? thanks John

+4
source share
2 answers

I also have a User object (based on the view) and several tables with CreatedByUser and ModifiedByUser links.

This works for me without getting the "must be zero" error:

  • In the "Note" object: right-click: "Add> Association ...".
  • Select "User" as the right side of the "Final Entity".
  • Change the multiplicity: “Notes” should be “Many”, and “User” should be “One”.
  • Deselect the navigation property on the right, as I will never move from the "User" to other tables: but this is up to you.
  • If you have the “CreatedBy” and “ModifiedBy” properties, you can change the association name to something more meaningful (for example, change “NoteUser” to “NoteCreatedByUser”
  • The same for the navigation property (for example, change "User" to "Created ByUser")
  • Leave "Add foreign key properties ...." unchecked.
  • Click OK.
  • IMPORTANT: in the "Properties" window, go to "Link restriction" and click the ellipsis.
  • Select "User" as Principal.
  • Change the dependent property to the appropriate value (for example, "CreatedBy")
  • Click OK.

Done!

Screenshot from my project below.

enter image description here

+2
source

My guess is that the association on the User object is user-defined, and the username is the candidate key (has a unique index defined on it) in SQL Server. Although you can create relationships based on this setting in SQL Server, the current version of EF does NOT support the creation of associations based on candidate keys: In EF (3.5 and 4.0) FKs MUST specify Primary keys.

The only way to do this is to create a new int field inside the Note table (e.g. UserId), and then create a new relationship between User.Id (PK) and Note.UserID (FK) and EF will happily create an association based on this for you.

+1
source

All Articles