У меня есть 2 классов (лиц) Exemption и период, и я хочу, чтобы сделать уникальный индекс с IDNumber от освобождения и Ид от периодаasp.net ядро создает ограничение на две колонки, одна из которых является другой объект
public class Exemption
{
[Key]
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
.
.
.
[Required]
public string IdNumber { get; set; }
[Required]
public Period Period { get; set; }
}
public class Period
{
[Key]
public int Id { get; set; }
.
.
.
[Required]
public string Year { get; set; }
}
Использование Fluent API я добавил .HasIndex внутри OnModelCreating но получил ошибку
builder.Entity<Exemption>().HasIndex(c => new { c.IdNumber, c.Period }).IsUnique();
получил следующее сообщение об ошибке при добавлении миграции
The properties expression 'c => new <>f__AnonymousType5`2(IdNumber = c.IdNumber, Id = c.Period.Id)' is not valid. The expression should represent a property access: 't => t.MyProperty'. When specifying multiple properties use an anonymous type: 't => new { t.MyProperty1, t.MyProperty2 }'.
я попытался добавить c.Period.Id
builder.Entity<Exemption>()
.HasIndex(c => new { c.IdNumber, c.Period.Id }).IsUnique();
получил следующую ошибку
The property 'Period' cannot be added to the entity type 'Exemption' because a navigation property with the same name already exists on entity type 'Exemption'.
мне нужно разрешить только один Exemption за IDNumber в Period.Id как Я делаю это в EF Core 1.0?