我正在尝试首先使用代码为 asp.net mvc 应用程序生成数据库。OrderItem 类确实生成为数据库中的 OrderItems 表,但我最终无法访问它。我该怎么做才能允许以下例如:db.OrderItems.Find(id);
模型如下:
namespace CustomerOrders.Models{
public class Customer
{
public virtual int CustomerID { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Company { get; set; }
public virtual string Email { get; set; }
public virtual string EmailCheck { get; set; }
}
public class Order
{
public virtual int OrderID { get; set; }
public virtual int CustomerID { get; set; }
public virtual DateTime OrderDate { get; set; }
public virtual double OrderTotal { get; set; }
public virtual double Tax { get; set; }
public virtual Customer Customer { get; set; }
public virtual List<OrderItem> OrderItems { get; set; }
}
public class OrderItem
{
public virtual int OrderItemID { get; set; }
public virtual int OrderID { get; set; }
public virtual int ProductID { get; set; }
public virtual double PricePerItem { get; set; }
public virtual double Quantity { get; set; }
public virtual Product Product { get; set; }
public Order Order { get; set; }
}
public class Product
{
public virtual int ProductID { get; set; }
public virtual string Title { get; set; }
public virtual string Description { get; set; }
public virtual double Price { get; set; }
}
}