Michael O'Dea-Jones' Blog

A relationship is being added or deleted from an AssociationSet ‘x’ EF issue

I'm still cutting my teeth on the Entity Framework (EF) and have just worked out why I have been receiving this kind of exception:

A relationship is being added or deleted from an AssociationSet 'FK_Shift_ShiftStatus'. With cardinality constraints, a corresponding 'Safety_Shift' must also be added or deleted.

Here is the code:

shift.Status = context.ShiftStatuses.First(x => x.Id == Status.ShiftStartedId);

EF Model:

Shift * <=> 1 ShiftStatus

Database:

Shift.ShiftStatusId has a Foreign Key Relationship with ShiftStatus.Id

After searching the Internet, I was none the wiser. I thought that maybe there was something theoretical that I was missing. In fact the only mistake I had made was that I didn't load the Shift Status reference before assigning it:

shift.StatusReference.Load();

shift.Status = context.ShiftStatuses.First(x => x.Id == Status.ShiftStartedId);

 

Published Sunday, November 08, 2009 9:34 AM by michael@wardyit.com

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit