MICHELVANDERVLUGT.NET RSS 2.0
 Wednesday, May 21, 2008

This week I ran into a quite unexpected exception that was thrown when I tried to remove an object from my LINQ ToSQL DataContext:

System.InvalidOperationException: An attempt was made to remove a relationship between a Master and a Detail. However, one of the relationship's foreign keys (Detail.MasterId) cannot be set to null..

The example in which this occurred isn't very exotic, just a Master table and a Detail table and a relationship with a foreign key MasterId in the Detail table (which doesn't allow null's). So it should be perfectly valid to remove a row from the Detail table and submit the changes.

 

Unfortunately there is a problem with this in LINQ To SQL, which is best explained by this post of Beth Massi. She states that to work around this problem you have to manually alter the dbml using an XML editor and add DeleteOnNull="true" to the association. And yes, this solves the problem. 

 

Beth discovered this problem in VS2008 Beta 2 and it still exists in the final release. Let's hope the problem is solved with the upcoming SP1...

Wednesday, May 21, 2008 8:06:22 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0] -

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Categories
Archive
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Michel van der Vlugt
Sign In
All Content © 2008, Michel van der Vlugt
DasBlog theme 'Business' created by Christoph De Baene (delarou)