【发布时间】:2014-03-29 06:37:59
【问题描述】:
我正在使用 EF 6 并且有以下内容
public class Title : EntityBase
{
public short Id { get; set; }
public string TitleName { get; private set; }
}
public abstract class EntityBase
{
public DateTime CreatedDate { get; set; }
}
而 DbContext 包含
public DbSet<Title> Titles { get; set; }
还有
modelBuilder.Entity<Title>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("Titles");
});
但在尝试访问标题时,我得到“实体类型 EntityBase 不是当前上下文模型的一部分。”在 NuGet 控制台中运行 Update-Database 后,我看到在数据库中创建了表“标题”,其中所有字段(id、titlename、createddate)都符合预期。如果可能,我不想在 DbContext 中添加 EntityBase 数据库集。请帮助我找到解决方案。
【问题讨论】:
标签: c# entity-framework ef-code-first