簡體   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