I have a table Transactions
with 4 Foreign Key references to an Employee
table - all nullable INT fields. I create a record in Transactions
with 3 of the Employee fields populated. If I then update the remaining null Employee field I get the error:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.GetOtherEndOfRelationship(IEntityWrapper wrappedEntity)
I found this SO question which helped me identify the cause, but I still don't understand WHY it happens - Can anyone explain the reason it occurs?
My workaround is to make sure all Employee FK fields are populated on creation of the Transactions
.
EDIT - this is not a duplicate- it has NOTHING to do with a simple check for null.