Categories
c# entity-framework entity-framework-6 sql sql-server-2008

Entity Framework 6: Multicolumn unique index featuring navigation property

How can I set multicolumn index on model like that:

public class Meta
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public Guid Id { get; set; }
[Index("MetaPeriodDateUnq", IsUnique = true, Order = 2)]
[Required]
public DateTime Date { get; set; }
[Index("MetaPeriodDateUnq", IsUnique = true, Order = 1)]
[Required]
public virtual PeriodType Period { get; set; }
/*
...
*/
}
public class PeriodType
{
[Key]
public Guid Id { get; set; }
/*
...
*/
}

After DB initialization there is only “MetaPeriodDateUnq” index mentioning Meta.Date column, but I’m relying on Meta.Date + Meta.Period.Id uniqueness.