我是EF4 CTP5的新手,我想在下面创建一个模型,每个表都是相同的字段(id,text,value),我不想将它们全部放在一个表中,我可以使用基类吗? ?但我不知道它是如何成为我的域名模型的?
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
答案 0 :(得分:2)
在您指示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; }
}
答案 1 :(得分:0)