0
我有一個項目,我試圖實現(看似)簡單的購物車。以下是相關實體。我經常收到各種各樣的錯誤,而不是無法處理order_Id列名稱。所以我懷疑訂單和物品之間的關係出了問題,但我也認爲在方法上可能會有更大的缺失。任何意見,將不勝感激。實體框架關係 - sql錯誤
public class Item
{
public int Id { get; set; }
public byte[] Thumbnail { get; set; }
public decimal Price { get; set; }
public string Name { get; set; }
public bool OnSale { get; set; }
public string Description { get; set; }
}
public class Order
{
public int Id { get; set; }
[ForeignKey("User")]
public virtual int UserId { get; set; }
public string Country { get; set; }
public decimal Total { get; set; }
public System.DateTime OrderDate { get; set; }
public virtual IList<Item> Items { get; set; }
public virtual User User { get; set; }
}
public class MyCart
{
[Key]
[ForeignKey("User")]
public int UserId { get; set; }
public virtual User User { get; set; }
public string MyCartId { get; set; }
public IDictionary<Item, int> ItemsHash { get; set; }
}
public class User
{
public int Id{ get; set; }
public int CreditCard { get; set; }
public string Country { get; set; }
public int CCExpMonth { get; set; }
public int CCExpYear { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual IList<Order> Orders { get; set; }
public virtual MyCart Cart { get; set; }
}
我是由一個單一的OrderId的列如何能夠使用在項目困惑實體,因爲一個項目必然屬於許多訂單。同樣,當訂單實體沒有名爲「訂單」的屬性時,怎麼會有訂單的逆向屬性。 除了我缺乏理解,update-database命令失敗,因爲Item實體中的'Order'屬性的反向屬性屬性無效,並且屬性'Orders'也不是Order實體上的有效導航屬性。 – britzkopf
確定@britzkopf答案已更新。 – Iraj
仍然沒有快樂。軟件包管理器錯誤讀取: 參數objname不明確或聲明的objtype(COLUMN)錯誤。 – britzkopf