我有以下两个类:
现在,当我更新数据库时,出现以下错误:
public class Tip
{
public string Home { get; set; }
public string Away { get; set; }
public string Prediction { get; set; }
public Tipster Tipster { get; set; }
... other properties
}
public class Tipster
{
public int Id { get; set; }
public string Username { get; set; }
public string Platform { get; set; }
}
现在,我想在Tip表中创建唯一索引。根据EF Core文档,没有数据注释语法,因此我使用流畅的语法:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Tip>()
.HasIndex(entity => new { entity.Tipster, entity.Home, entity.Away, entity.Prediction })
.HasName("IX_UniqueTip")
.IsUnique();
}
现在,当我更新数据库时,出现以下错误:
看起来EF不喜欢我在索引中使用引用属性。我该如何修复?C:..>dotnet ef database update System.InvalidOperationException: 因为它被配置为导航属性,所以无法为实体类型“Tip”上的属性“Tipster”调用Property。Property只能用于配置标量属性。