How to specify a multi-column UNIQUE constraint in code-first Entity Framework fluent API
问题 Suppose I have the following entities: public class Calendar{ public int ID{get;set;} public ICollection<Day> Days { get; set; } } public class Day{ public int ID{get;set;} public DateTime Date{get;set;} public int CalendarID{get;set;} } This is a one-to-many relationship with CalendarID as a foreign key. The issue is I also want to make sure that each date exists only once in each calendar. That is, no two days have both the same Date and same CalendarID . In raw SQL I can do this by: ALTER