繁体   English   中英

实体框架外键定制

[英]Entity Framework Foreign Key customization

我使用的是Entity Framework 6.0,我知道FK的用途,我需要对其进行一些调整。

这是示例代码片段

class CommonMaster
{
      public int ID {get;set;}
      public string Name {get;set;}
      public string Value {get;set;}
      public string Type {get;set;}
}

class BankDetails
{
  //all relevant fields
  public int CustomerType {get;set;}  //expected by ef

  public string CustomerType {get;set;} //the one i want
  [ForeignKey("CustomerType")] //expected by ef
  public virtual CommonMaster CommonMaster_CustomerType {get;set;}
}

默认情况下,连接将是

from BankDetails bd join CommonMaster cm on bd.CustomerType = cm.Value

默认情况下,这里是ef查询

[table1_fk] = [table2_pk]

我想要的是

[table1_somefield with codevalue]= [table2 _ code value]

如果不可能,您能否提供实现这一目标的最佳选择?

谢谢,

这取决于您要使用的策略。 对于“代码优先”,可以这样进行。 外键EF

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM