Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework One-To-One Mapping Issues

Using VS 2010 beta 2, ASP.NET MVC.

I tried to create an Entity framework file and got the data from my database.

There were some issues with the relationships, so I started to tweak things around, but I kept getting the following error for simple one-to-one relationships

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

My Users table is consists of some other many-to-many relationships to other tables, but when I try to make a one-to-one relationship with other tables, that error pops up.

Users Table

  • UserID
  • Username
  • Email

etc..

UserProfiles Table

  • UserProfileID
  • UserID (FK for Users Table)
  • Location
  • Birthday
like image 902
Omar Avatar asked Nov 19 '09 06:11

Omar


1 Answers

For one-to-one relationships, EF expects that the tables are using the same primary key. And really, if it's a true one-to-one they probably should. So in your example, if you make UserID the primary key on the UserProfiles table, your one-to-one will work.

like image 86
Jacob Proffitt Avatar answered Sep 28 '22 02:09

Jacob Proffitt