我收到EntityType 'User' has no key defined. Define the key for this EntityType
错误。
型号:
public abstract class KeyedEntityBase
{
public int ID { get; private set; }
}
public class User : KeyedEntityBase
{
public string UserName { get; private set; }
public string EmailAddress { get; private set; }
}
上下文:
public class LSBPortalContext : DbContext
{
public LSBPortalContext()
: base("LSBPortalDB")
{
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("User");
});
base.OnModelCreating(modelBuilder);
}
}
答案 0 :(得分:1)
问题是我实际上没有映射KeyedEntityBase类。一旦我这样做,一切都正常。