Issues with Entity Framework One-to-One Mapping

entity-framework

Question

ASP.NET MVC is used in VS 2010 beta 2.

I made an effort to develop an Entity framework file using data I had in my database.

The relationships had some problems, so I tried to change things, but I kept receiving the following error for straightforward one-to-one connections.

Error 1 Error 113: Multiplicity is not valid in Role 'UserProfile' in relationship 'FK_UserProfiles_Users'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *. myEntities.edmx 2024

When I attempt to create a one-to-one connection with other tables, an error appears even if my Users database has many additional many-to-many links to other tables.

People Table

  • UserID
  • Username
  • Email

etc..

Table of UserProfiles

  • UserProfileID
  • UserID (FK for Users Table)
  • Location
  • Birthday
1
46
7/20/2014 1:17:01 AM

Accepted Answer

EF anticipates that the tables will be utilizing the same primary key for one-to-one connections. And if it's a genuine one-to-one conversation, they most likely should. Therefore, in your example, the one-to-one relationship will function if UserID is set as the primary key on the UserProfiles database.

66
11/19/2009 7:00:37 AM

Popular Answer

In my case, the problem involves a sale and layaway arrangement.

Both a layby and a sale may happen independently of one another. This signifies that my relationship ranges from zzz-9 to zzz-13.

Layby makes reference to Sale, but neither Layby nor Sale may utilize the main key of the other.

I used a 0 or 1 to many relationship to address the issue, changed the sale's "Laybys" getter and setter to private, and then included my own "Layby" getter and setter in my POCO.



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