0

I always have problems with relations beetween classes in code first when there is several relations beetweens classes.

I have a User class and a Review class. A user that can send messages have a list of reviews. A review have a sender and a receiver.

 public class Review
{
    [Key]
    public int Id { get; set; }
    public int IdReceiver { get; set; }
    public int IdSender { get; set; }

    [ForeignKey("IdSender")]
    public virtual User Sender{ get; set; }

    [ForeignKey("IdReceiver")]
    public virtual User Receiver{ get; set; }
}

 public class User
{
    [Key]
    public int Id { get; set; }
    public virtual List<Review> Reviews { get; set; }
}

I want to be able to get the list of the reviews of a user with a user object. (Why I put the review list in the User class). With a review, I need to have access to the sender and the receiver.

I need to make relations beetween these tables but when I try, I have too many relations.

Do I need something to make several navigation properties beetween 2 classes and how to create there relations in a good way?

Also, I have often delete on cascade errors. I heard about fluent API but not really.

0 Answers0