【发布时间】:2015-07-06 21:01:20
【问题描述】:
我有一个项目,我正在尝试实现一个(看似)简单的购物车。以下是相关实体。我经常遇到各种错误,这与 order_Id 列名无效有关。所以我怀疑订单和项目之间的关系有问题,但我也认为在方法方面我可能遗漏了一些更大的东西。任何意见,将不胜感激。
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; }
}
【问题讨论】:
标签: .net entity-framework model-view-controller ef-code-first