我正在使用EF代碼的第一種方法,並希望添加一個鏈接(地圖)表。我工作過下面的例子,並出現以下錯誤:實體框架代碼第一張圖(鏈接)表?
System.Data.Entity.Edm.EdmEntityType: : EntityType 'EmployeeDepartmentLink' has no key defined. Define the key for this EntityType.
問題是我不希望在這個表中的鍵,它只是映射的兩個表一起:
public class Employee
{
[Key()]
public int EmployeeID;
public string Name;
}
public class Department
{
[Key()]
public int DepartmentID;
public string Name;
}
public class EmployeeDepartmentLink
{
public int EmployeeID;
public int DepartmentID;
}
我已經嘗試了各種類似於添加「[Key()]」屬性的東西,但它沒有意義,它將被使用,以及我將它添加到哪個字段?我想知道這種表模型是否被支持?
選中此http://stackoverflow.com/questions/5482670/entity-framework-code -first-define-the-key-for-this-entitytype – Sampath