0

我收到一个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);
    }
}
4

1 回答 1

1

问题是我实际上并没有映射 KeyedEntityBase 类。一旦我这样做了,它就一切正常。

于 2012-07-14T04:12:41.973 回答