C# EF4 CTP5代码优先建模问题

C# EF4 CTP5代码优先建模问题,c#,entity-framework,entity-framework-4,entity-framework-4.1,ef-code-first,C#,Entity Framework,Entity Framework 4,Entity Framework 4.1,Ef Code First,我是EF4 CTP5的新手,我想在下面创建一个模型,比如,每个表都是相同的字段(id、文本、值),我不想把它们都放在一个表中,我可以使用基类吗?但我不知道它是如何成为我的域模型的 public class BaseSearchType { public int Id {get;set;} public int text{get;set;} public int value {get;set;} } public class BooleanSearchTypeTable :Ba

我是EF4 CTP5的新手,我想在下面创建一个模型,比如,每个表都是相同的字段(id、文本、值),我不想把它们都放在一个表中,我可以使用基类吗?但我不知道它是如何成为我的域模型的

public class BaseSearchType
{
   public int Id {get;set;}
   public int text{get;set;}
   public int value {get;set;}
}

public class BooleanSearchTypeTable :BaseSearchType
{

}

public class JobStatusSearchTypeTable:BaseSearchType
{

}

public class PersonStatusSearchTypeTable: BaseSearchType
{

}
桌子

BooleanSearchTypeTable 
-----------------
id text value
1   All  0
2   Yes  1
3   No   2

JobStatusSearchTypeTable
-----------------
id text value
1   Open  0
2   Closed  1
3   Approved   2
4   Rejected 3
5   Waiting 4

PersonStatusSearchTypeTable
id text value
1   Work 0
2   Seek 1
3   Vacation 2
尝试使用“POCO”模型,在这种情况下可能会有所帮助


除非您指示EF这样做,否则它们不会映射到一个表中。只需定义您的类,如:

public abstract class BaseSearchType
{
    public int Id { get; set; }
    public string text { get; set; }
    public int value { get; set; }
}

public class BooleanSearchTypeTable : BaseSearchType
{ }

public class JobStatusSearchTypeTable : BaseSearchType
{ }

public class PersonStatusSearchTypeTable : BaseSearchType
{ }
你的背景是:

public class Context : DbContext
{
    public DbSet<JobStatusSearchTypeTable> JobStatuses { get; set; }
    public DbSet<BooleanSearchTypeTable> BooleanStatuses { get; set; }
    public DbSet<PersonStatusSearchTypeTable> PersonStatuses { get; set; }
}
公共类上下文:DbContext
{
公共数据库集作业状态{get;set;}
公共数据库集布尔状态{get;set;}
公共DbSet personstatus{get;set;}
}

您应该升级到发布版本。已经有一个多月了。EF 4.1您不仅可以设置基类dbset,例如公共dbset BaseSearchType{get;set;}。一旦您这样做,您就可以将实体继承和所有实体映射到单个表,这是OP不想要的。您可以将其修改为其他类型的继承,但仍然只有在需要时才应该这样做。