I'm struggling to get my head around the sql exception:
FK contstraint may cause cycles or multiple cascade paths
I know there are many posts relating to it here on SO, for example: https://stackoverflow.com/a/852047/1778169 and https://stackoverflow.com/a/17127512/1778169
I have read them a few times, but I still don't understand:
- exactly what this error means, and
- how I can design models to avoid it
My attempt at understanding - have I got this right?
In the models below, User is required for both ForumThread and ForumPost entities.
Deleting a User will cascade like this: User > ForumThread > ForumPost
and also like this: User > ForumPost
, thus giving me 'multiple cascade delete paths'.
public class ForumThread
{
public int ID {get;set;}
public int UserID {get;set;}
public User User {get;set;}
public Collection<ForumPost> Posts {get;set;}
}
public class ForumPost
{
public int ID {get;set;}
public int UserID {get;set;}
public User User {get;set;}
public int ForumThreadID {get;set;}
public int ForumThread Thread {get;set;}
}
public class User
{
public int ID {get;set;}
public int UserID {get;set;}
public User User {get;set;}
public Collection<ForumThread> Threads {get;set;}
}
If I have understood this correctly, then how would I design the models so that a User is required for both ForumThread and ForumPost entities?
I'd like the User property on the ForumThread to identify and list threads started by a particular user.
I guess one option would be to select threads by identifying the user who made the first post. But isn't that overly complicated for something that should be quite simple?