I have two tables FilesystemEntries and CacheEntries where there is an association of 0..1 CacheEntry per FilesystemEntry (that is a FilesystemEntry can have a null CacheEntry, but not vice-versa). Initially, the CacheEntry for all FilesystemEntries is null. I'm having trouble changing this (adding a new CacheEntry). The code (truncated) looks like this:
FilesystemEntry filesystemEntry; // Already exists in database
CacheEntry cacheEntry; // A new one is created
// ...
filesystemEntry.CacheEntry = cacheEntry; // Was null before (verified in debugger)
cacheEntry.FilesystemEntry = filesystemEntry;
_db.AddToCacheEntries(cacheEntry);
However, I'm recieving the following error:
System.Data.UpdateException: A relationship is being added or deleted from an
AssociationSet 'FK_CacheEntries_0'. With cardinality constraints, a corresponding
'CacheEntries' must also be added or deleted.
Any entity framework wizards know what's going on?
Similarly, is there any way to allow the database to handle the "ON DELETE CASCADE" (I'm using sqlite, so it'll be via a trigger)? This would be a lot more convenient and future-proof than specifying all the deletes in the DAL.