我想在EF代碼中建立多對多的關係,但默認約定是錯誤的。以下類別描述了這種關係:如何使用實體框架流暢的API配置多對多的關係
class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
class Account
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
一個帳戶可以有許多產品。
然而,EF約定將創建數據庫表爲:
Products Table
--------------
Id
Name
Account_Id <- What is this?
Accounts Table
--------------
Id
Name
這看起來並不像一個多到多表結構?我如何配置流暢API以反映關係並創建中間表:
AccountProducts Table
---------------------
Account_Id
Product_Id
是不是要一個多對多的? –
謝謝 - 編輯標題以反映正確的含義 – Fixer
格式良好的問題。容易明白。 –