Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.0: Error 113: Multiplicity is not valid in Role

I have put a new table in my database and there are 4 tables that have a foreign key relationship with it. I thought I configured all 4 in the same way, but I get this error;

Error 15 Error 113: Multiplicity is not valid in Role 'ReportCellImage' in relationship 'FK_OtherLeaves_ReportCellImages'. Because all the properties in the Dependent Role are nullable, multiplicity of the Principal Role must be '0..1'.

So to simplify my tables;

ReportCellImage table contains the ReportCellImageId field which in the primary key and an integer

OtherLeave table contains the ReportCellImageId field as a nullable foreign key with a default of 4

The other tables are similar and all have a foreign key configured to join with the ReportCellImage table

This is a recent change, so when I update my edmx file from the database, why do I get this error and how do I fix it?

like image 308
arame3333 Avatar asked Feb 15 '12 11:02

arame3333


2 Answers

I just had the same message and it was perplexing because the tables I modified in the DB were different from the ones I was getting the message for.

I tried changing the multiplicity 0..1-to-many but the message persisted, even after "Run Custom Tool" commands, cleans and rebuilds.

Resolved by dropping the relationship EF was complaining about and updating the model from DB

like image 62
Sten Petrov Avatar answered Oct 03 '22 01:10

Sten Petrov


If your FK is nullable your multiplicity in principal entity must be 0..1 - default value has no role in this because you can assign null to FK. So all your dependent entities must be in 0..1 - * relation with your principal entity.

like image 31
Ladislav Mrnka Avatar answered Oct 03 '22 02:10

Ladislav Mrnka