【发布时间】:2010-09-01 17:13:36
【问题描述】:
我有一张大表,想映射到几个实体。
假设表格如下所示:Thing(ThingId, Property1...Property20)
现在我有了我的实体:
public abstract class ThingBase
{
public int ThingId { get; set; }
public string Property1 { get; set; }
public string Property2 { get; set; }
}
public class ThingSummary : ThingBase
{
public string Property3 { get; set; }
}
public class Thing : ThingBase
{
public string Property3 { get; set; }
//...
public string Property20 { get; set; }
}
如何设置我的 DbContext 以使其正常工作?我有:
public DbSet<ThingSummary> ThingSummaries { get; set; }
public DbSet<Thing> Things { get; set; }
但我收到错误“无效的对象名称'dbo.ThingSummaries'。”当我尝试查询时。
我已尝试添加到 OnModelCreating:
modelBuilder.Entity<ThingSummary>().MapSingleType().ToTable("Things");
但这似乎没有任何作用。
有什么想法吗?
【问题讨论】:
标签: entity-framework entity-framework-4 ef4-code-only