I have a multi-client DB (multitennant) with several tables.
Two of these tables are tblEmployees and tblTitles.
Now I have a relationship from tblEmployees.empTitle to tblTitles.ttlID.
That far everything is working.
But now I have to make the application for multiple clients/tennants.
So I added the fields tblEmployees.empClient and tblTitles.ttlClient and included them into the association.
This works fine for reading and for setting the persons title as well.
But if I try to remove the title (set it to NULL), SQL to Linq tries to modify both tblEmployees.empTitle and tblEmployees.empClient with is not allowed because tblEmployees.empClient is part of the primary key.
And so I get the following error:
InvalidOperationException:
An attempt was made to remove a relationship between a AppTitle and a AppEmployee.
However, one of the relationship's foreign keys (AppEmployee.clientID, AppEmployee.titleID) cannot be set to null.
How can I tell SQL to Linq only to modify field tblEmployees.empTitle???
I just solved the problem as everyone else did:
I let LinqToSQL think, clientID was not part of the primary key and removed it from the association.
However I did not modify the database, so the database still enforces to use a title of the same client/tennant.