这是我的数据库代码:
public class User {
public int Id {get; set;}
public ICollection<Vote> Votes {get; set;}
public User() {
Votes = new List<Vote>();
}
}
public class Video {
public int Id {get; set;}
public int OnsiteId {get; set;}
public ICollection<Vote> Votes {get; set;}
public Video() {
Votes = new List<Vote>();
}
}
public class Vote {
public int Id {get; set;}
public int UserId { get; set; }
[ForeignKey("UserId")]
public User User { get; set; }
public int VideoOnsiteId { get; set; }
[ForeignKey("VideoOnsiteId")]
public Video Video { get; set; }
}
出于某种原因,Votes
表包含VideoOnsiteId
列,而Video.Id
代替Video.OnsiteId
。结果是我无法向数据库添加一行,因为我对FOREIGN KEY约束感到困惑。我怎么能改变它?