2012-04-05 81 views
0

對於簡單的FK我可以通過使用實體框架代碼第一逆屬性生成列名

[ForeignKey("CustomList1")] 
    public int? CustomList1ID { get; set; } 
    public virtual CustomList CustomList1 { get; set; } 

但inverseProperty更改生成列名(因爲我有多個customList,如何控制對生成列名數據庫?

[InverseProperty("CustomList1")] 
    public virtual List<Customer> CustomerCustomList1 { get; set; } 

回答

0

[ForeignKey的( 「CustomList1」)不改變生成列名。

  1. 如果放置在導航屬性上,它將指定用於檢索正確實體的字段的名稱。
  2. 如果放置在字段屬性,它指定使用該字段作爲FK關聯的導航屬性。

如果要更改生成的列名稱,應該使用: [Column(「YOU_COLUMN_NAME」)]。

+0

我知道ForeignKey(「CustomList1」)不會更改列名稱,但下一行顯式添加一個FK鍵會得到我需要的名稱。 我也知道專欄(「myname」)將爲簡單的FK做,但對於InverseProperty它似乎不工作。 – neogeo 2012-04-20 17:40:40

相關問題