【发布时间】:2017-12-21 14:42:03
【问题描述】:
我有以下两个类
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 文档,没有 Data Annotations 语法,所以我使用的是流利的:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Tip>()
.HasIndex(entity => new { entity.Tipster, entity.Home, entity.Away, entity.Prediction })
.HasName("IX_UniqueTip")
.IsUnique();
}
现在,当我更新数据库时,出现以下错误
C:..>dotnet ef 数据库更新 System.InvalidOperationException: 无法在实体类型“提示”上调用属性“提示者”的属性 因为它被配置为导航属性。财产只能 用于配置标量属性。
似乎 EF 不喜欢我在索引中使用引用属性这一事实。我该如何解决?
【问题讨论】:
标签: c# ef-core-2.0