I am trying to understand how to represent user-friendliness with Entity Framework (5) Code First. My initial idea was to create a Friendship class that contains references to two user instances, so friendship is represented by separate objects.
public class Friendship { public virtual int Id { get; set; } [Required] public virtual UserProfile User1 { get; set; } [Required] public virtual UserProfile User2 { get; set; } [Required] public virtual DateTime Since { get; set; } } [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } [Required] public string UserName { get; set; } }
When trying to create a database through EF Migrations, however, I came across due to an SQL error:
Introducing FOREIGN KEY constraint 'FK_dbo.Friendships_dbo.UserProfile_User2_UserId' on table 'Friendships' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Suggestions on how to solve this problem would be very welcome.
source share