我在.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,因为它被配置为导航属性。属性只能用于配置标量属性。