I have two tables which are kind of problematic.
The first table is about users and has -
userId, username, password, etc
.The second is handling messages, so it has -
messageId, senderId, receiverId,
messageContent.
As you can see, both senderId
and receiverId
need to be related to userId from the users table.
But as I'm trying to use Code First, it just crashes. I get an exception :
"Introducing FOREIGN KEY constraint 'FK_dbo.Messages_dbo.Users_ReceiverId' on table 'Messages' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints."
This is how I made the relations in the Message class :
[ForeignKey("Sender")]
public int SenderId { get; set; }
public virtual User Sender { get; set; }
[ForeignKey("Receiver")]
public int ReceiverId { get; set; }
public virtual User Receiver { get; set; }
Any ideas? I'm stuck right now. It works perfectly fine if I do it database-first, but not if I try it Code First.