c# - Entity Framework foreign key InvalidOperationException -
is there way somehow output more details/information when invalidoperationexception 1 happens during savechanges()
call?
the operation failed: relationship not changed because 1 or more of foreign-key properties non-nullable. when change made relationship, related foreign-key property set null value. if foreign-key not support null values, new relationship must defined, foreign-key property must assigned non-null value, or unrelated object must deleted.
i not removing db questions similar 1 didn't me. message quite self-explanatory, true, can't see mistake in code , helpful if exception gave more information property , foreign key in question.
edit - have checked innerexception , it's empty.
for example, if have next structure:
public class client { public int clientid { get; set; } public string name { get; set; } public int clienttypeid { get; set; } public clienttype clienttype { get; set; } } public class clienttype { public int clienttypeid { get; set; } public string description { get; set; } }
if changing "name" propertie example, property "clienttype" must null, otherwise try create,update or delete client type.
so set clienttype null, before savechanges();
if post more of code, can sure exactlly it's happening, guess
Comments
Post a Comment