Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding "Conflicting changes to the role" Exception

Actually I am getting an exception

Conflicting changes to the role 'TableName' of the relationship 'DataModel.FK_TableName_RelateTableName' detected

when ApplyChanges method is called from the ObjectContext. I dont have any idea what this exception is all about. I just wanted to know the cause of this exception.

like image 925
Anis Ghee Avatar asked May 16 '10 07:05

Anis Ghee


1 Answers

I think you get these sorts of exceptions if you are trying to get the foreign key relationship for the same entity twice. A simple example would be this:

var tn = ctx.TableName.Where(t => t.TableNameId == 1).First();
var rel = new RelateTableName {TableName = tn, TableNameId = 2};
ctx.RelateTableName.AddObject(rel);

Here you can see that I set the TableNameId property to 2 but the TableName property to an object with the TableNameId of 1 - so the entity framework cannot work out which one is the correct relationship to put into the database.

like image 188
kmp Avatar answered Nov 15 '22 23:11

kmp