【发布时间】:2015-06-18 04:24:50
【问题描述】:
我正在使用 Entity Framework 6.0,我知道 FK 的用途,我需要对其进行一些调整。
这是示例代码sn-p
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]
如果不可能,您能否提供一个最佳替代方案来实现这一目标?
谢谢,
【问题讨论】:
标签: c# sql .net sql-server