My old Linq-to-Entities project came back to haunt me.
I had to make some changes to the DB to allow a couple things, and with that, I changed some INT NOT NULL REFERENCES
change to INT REFERENCES
- the obvious difference being that they now allowed null values.
No big deal really, I went into my .edmx file and did 'Update Model from Database' and everything seemed to be working fine, until I tried a certain operation that kicked out this doozy:
A relationship is being added or deleted from an AssociationSet 'FK__Gizmo__CategoryI__0425A276'. With cardinality constraints, a corresponding 'Gizmo' must also be added or deleted.
Now those arent the actual values, but you get the idea.
This is telling me that my Foreign Key relationship is being violated, which confused me.
I had changed that FK to be nullable, so this should not be happenening.
I then tried the same operation in SQL Server Management Studio, just to be sure it was legal on the SQL side, and it worked fine.
So I figured, like so many times before, the problem lies with Linq-to-Entities.
I opened my .edmx and saw something like this:
As you can see, it clearly shows a one-to-many relationship from Category->Gizmo.
This was no longer the case, but L2E failed to pick up on it.
The bottom line is that 'Update Model from Database' did not catch the Foreign Key change
Once I figured this out, it is a simple to fix.
Simply right-click on the relationship (in the box above) and click 'Properties'; that will bring up the Properties dialogue.
Once this is open, change the End of the referenced table from '1 (One)' to '0...1 (Zero or One)' and save your .edmx.
This should not be necessary as you would assume 'Update Model from Database' would catch things like this, but like so many other things in L2E, it just doesn't work like you want it to.
I can't wait for .Net 4.0, supposedly most of the problems with L2E are getting fixed; we'll just have to wait and see.