2014-04-11 53 views
0

我有一个MasterConfig表,我想以CodeValue格式存储我的值。即在实体框架中使用不同名称映射外键两次

ID CODE   VALUE 
1. BusinessType IT 
2. BusinessType Marketing 
3. ContractType General 
4. ContractType Custom 

所以,基于CODE字段获取记录。例如。 getCodeValue/ContractType

现在,我有一个合同表,我必须将这些字段映射为外键。我的合同模式是这样的:

public class Contract 
{ 
    [Key] 
    public int ID{get; set;} 
    public string Name{get; set;} 

    [ForeignKey("CodeValue")] 
    public int BusinessTypeID{get; set;} 

    [ForeignKey("CodeValue")] 
    public int ContractTypeID{get; set;} 

    public virtual CodeValue CodeValue {get; set;} 
} 

在创建与视图控制器,我得到错误“无法检索承包模式元数据不能够映射该领域。”

请建议我在实体框架(ASP.NET MVC)中的这种主配置关系的解决方案?

回答

0

它需要对地图导航属性在Contract类,像这样 :

public class Contract 
{ 
    [Key] 
    public int ID { get; set; } 
    public string Name { get; set; } 

    [ForeignKey("BusinessType")] 
    public int BusinessTypeID { get; set; } 

    [ForeignKey("ContractType")] 
    public int ContractTypeID { get; set; } 

    public virtual CodeValue BusinessType { get; set; } 
    public virtual CodeValue ContractType { get; set; } 
} 
+0

工作就像魅力....非常感谢..使用 –

+0

上CodeValue所以,创建的各个派生类那些链接外键的类。 –

相关问题