0
是否有可能使用一個自動遞增的身份索引和一個將其鏈接到另一個表的外鍵映射實體?在實體框架4,一個身份和一個外部使用兩個鍵?
public class Item
{
public int ItemID { get; set; }
[StringLength(20)]
public string Barcode { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(50)]
public string Description { get; set; }
public decimal Price { get; set; }
[ForeignKey("ItemCategory")]
public string CatID { get; set; }
public virtual ItemCategory ItemCategory { get; set; }
}
public class ItemCategory
{
// This should be the identity index
public int ItemCategoryID { get; set; }
// This should be the foreign key
public string CatID { get; set; }
public string Name { get; set; }
public virtual ICollection<Item> Items { get; set; }
}
我看到這個answer - 我應該配置我的表使用模型構建器?
我沒有使用int索引,只是使用字符串作爲鍵,因爲它更重要。無論如何謝謝@拉迪斯拉夫姆爾卡 – Ron