Mapping Fail with Entity Framework

While beginning a new project for myself, I decided to use the Entity Framework by building my entities first then creating the database required to support the entities I need. When I reached the stage where I had to map the relationships to the database, I wasn't exactly sure what to put in. I eventually figure out that I need to set the table mapping to the table with the many multiplicity, then set the tables to their corresponding keys in that table.

I originally set them to the same key before I looked at how the designer did it if you generated the edmx from the database. When I set the relationships to the correct keys, I kept receiving the following error:

Error 113: Multiplicity is not valid in Role in relationship X. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be 1.

I kept twiddling with things, trying to get the error message to go away. It turned out that before you can change the column mapping, you have to click delete in the drop down before you can select another column and have it persist correctly. Also, for some reason, it really didn't like me editing the xml. Watch out for this if you prefer to create your entities before the database.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Monday, April 13, 2009 12:54 AM

Comments on this post

# re: Mapping Fail with Entity Framework

Requesting Gravatar...
Great tip! This issue was driving me around in circles. I think I did just this once before and it solved the issue, but I didn't realize that *this* was the action that did the trick. Thanks!
Left by Zack on Jun 11, 2010 1:28 PM

# re: Mapping Fail with Entity Framework

Requesting Gravatar...
This error also occurs if you map a PK to a PK

http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/f41b4300-4d54-4e1d-94e0-76630625e70c
Left by Anton on Nov 08, 2010 7:35 AM

Your comment:

 (will show your gravatar)