Come posso impostare l'indice multicolonna sul modello in questo modo:
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; }
/*
...
*/
}
Dopo l'inizializzazione del DB c'è solo l'indice "MetaPeriodDateUnq" che menziona la colonna Meta.Date, ma mi sto affidando all'unicità di Meta.Date + Meta.Period.Id.
È necessario includere esplicitamente la chiave esterna, in genere le annotazioni sulle proprietà di navigazione non funzionano.
[Index("MetaPeriodDateUnq", IsUnique = true, Order = 2)]
public DateTime Date { get; set; }
[Index("MetaPeriodDateUnq", IsUnique = true, Order = 1)]
public Guid PeriodId { get; set; }
public virtual PeriodType Period { get; set; }
Questo dovrebbe funzionare (non testato).