无法在实体类型'yyy'上为属性'xxx'调用Property,因为它被配置为导航属性?

时间:2017-12-14 17:06:37

标签: entity-framework .net-core entity-framework-core

我在.Net core 2.0应用程序(Asp.net core web api 2.0)中有以下模型

public class AddressPasscode
{
    [Key] // Key attribute doesn't work so I need to set it in OnModelCreating
    public SqlBytes Address { get; set; }
    public int Passcode { get; set; }
}

以下代码位于DB上下文

    public DbSet<AddressPasscode> AddressPasscodes { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AddressPasscode>().HasKey(e => e.Address);
    }

但是,这是modelBuilder.Entity<AddressPasscode>().HasKey(e => e.Address);

上的运行时错误
  

InvalidOperationException:无法为实体类型“AddressPasscode”上的属性“Address”调用Property,因为它被配置为导航属性。属性只能用于配置标量属性。

0 个答案:

没有答案