我有两张桌子: 产品和ProductReserved。
产品:
public int ProductID { get; set; }
public Nullable<int> BusinessEntityID { get; set; }
public string BarCode { get; set; }
public string PurchaseDescription { get; set; }
public string SaleDescription { get; set; }
public Nullable<decimal> SalePrice { get; set; }
public Nullable<decimal> CostPrice { get; set; }
public string TypeCategory { get; set; }
public Nullable<int> QuantityOnHand { get; set; }
public Nullable<int> QuantityOnPurchaseOrder { get; set; }
public Nullable<System.DateTime> PurchaseOrderArrivalDate { get; set; }
public string Bin { get; set; }
public string PictureLink { get; set; }
ProductReserved:
public int ProductReservedID { get; set; }
public Nullable<int> ProductID { get; set; }
public Nullable<int> SellerID { get; set; }
public Nullable<int> QuantityReserved { get; set; }
public Nullable<System.DateTime> ProductReservedDate { get; set; }
我创建了一个带有两个字段的模型MainTable。
public string BarCode { get; set; }
public string SaleDescription { get; set; }
public Nullable<decimal> SalePrice { get; set; }
public string TypeCategory { get; set; }
public Nullable<int> QuantityReserved { get; set; }
public Nullable<int> SellerID { get; set; }
当我想要填满新模型MainTable时,我在Controller中遇到问题。我正在尝试这样的事情:(我知道错了,这就是我需要帮助的原因)
MainTable prod = (from p in db.Products
join pr in db.ProductReserveds on p.ProductID equals pr.ProductID
select new
{
BarCode = p.BarCode,
SaleDescription = p.SaleDescription,
SalePrice = p.SalePrice,
TypeCategory = p.TypeCategory,
QuantityReserved = pr.QuantityReserved,
SellerID = pr.SellerID
}
);
此外,我应该如何返回此视图,以及我应该如何在视图上收到它?