Entity framework EF4的代码第一个CTP4-如何将多个实体(公共基)映射到单个表

Entity framework EF4的代码第一个CTP4-如何将多个实体(公共基)映射到单个表,entity-framework,entity-framework-4,ef4-code-only,Entity Framework,Entity Framework 4,Ef4 Code Only,我有一个大表,我想映射到几个实体 假设桌子看起来像这样:东西(ThingId,Property1…Property20) 现在我有了我的实体: public abstract class ThingBase { public int ThingId { get; set; } public string Property1 { get; set; } public string Property2 { get; set; } } public class ThingSu

我有一个大表,我想映射到几个实体

假设桌子看起来像这样:东西(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; }
publicdset ThingSummaries{get;set;}
公共DbSet Things{get;set;}
但是,当我尝试查询时,出现了一个错误“无效的对象名'dbo.ThingSummaries'。”

我已尝试将以下内容添加到OnModelCreating:

modelBuilder.Entity<ThingSummary>().MapSingleType().ToTable("Things");
modelBuilder.Entity().MapSingleType().ToTable(“东西”);
但这似乎没有任何作用


有什么想法吗?

我想你不能有什么总结。你只能拥有一些东西。您也不能使用MapSingleType,因为它表示只有单个类型将映射到表。您必须改用MapHiearchy。我在本文中发布了这种映射的示例