Asp.net mvc 如何通过大小、数量和颜色一次性获得库存价值
我有四种型号(商品、面料、生产、库存) 我想通过项目ID获得股票价值,如下所示:Asp.net mvc 如何通过大小、数量和颜色一次性获得库存价值,asp.net-mvc,linq,Asp.net Mvc,Linq,我有四种型号(商品、面料、生产、库存) 我想通过项目ID获得股票价值,如下所示: <table class="table-responsive"> <tr> <td>Color</td> <td>Size</td> <td>Quantity</td> </tr>
<table class="table-responsive">
<tr>
<td>Color</td>
<td>Size</td>
<td>Quantity</td>
</tr>
<tbody class="StockTbody"></tbody>
</table>
问题是:我想求数量的和
请帮助我想您正在这里寻找一个
群组:
public JsonResult StuckDetails (int ID)
{
var table = (from tb in db.Stocks
where ID == tb.Production.ItemID
group tb by new
{
tb.Production.fabric.Colors.ColorName,
tb.size.SizeName
} into grp
select new
{
color = grp.Key.ColorName,
size = grp.Key.SizeName,
Quantity = grp.Sum(g => g.Quantity)
});
return Json(table, JsonRequestBehavior.AllowGet);
}
它们Key.ColorName
属性名称可能会有所不同-我在这里不太确定。使用Intellisense引导您完成它
public class Colors
{
public int ID { get; set; }
[Display(Name ="Color")]
public string ColorName { get; set; }
public virtual List<Fabric> fabric { get; set; }
public virtual List<OrderDetail> OrderDetails { get; set; }
}
public class Item
{
public int ID { get; set; }
[Display(Name = "Item")]
public string ItemName { get; set; }
public int code { get; set; }
[Display(Name ="Collection")]
public Nullable<int> CollectionID { get; set; }
[Display(Name = "Category")]
public Nullable<int> CategoryID { get; set; }
public string Image { get; set; }
public string BarcodeImage { get; set; }
public string Barcode { get; set; }
public int NumberOfDraft { get; set; }
public decimal SectoralSellingPrice { get; set; }
public decimal wholesalePrice { get; set; }
public decimal discountPrice { get; set; }
public decimal wholesalevariegated { get; set; }
public decimal DesignCost { get; set; }
public int three { get; set; }
public virtual List<Production> production { get; set; }
public virtual Collection collection { get; set; }
public virtual Categories categories { get; set; }
public virtual List<OrderDetail> orderDetail { get; set; }
}
public class Stock
{
public int ID { get; set; }
public int ProductionID { get; set; }
public int SizeID { get; set; }
public int Quantity { get; set; }
public string ShelfNumber { get; set; }
public virtual Production Production { get; set; }
public virtual Size size { get; set; }
public virtual List<StockRemain> stockRemain { get; set; }
}
public JsonResult StuckDetails (int ID)
{
var table = (from tb in db.Stocks
where ID == tb.Production.ItemID
select new
{
color = tb.Production.fabric.Colors.ColorName,
ColorId=tb.Production.fabric.ColorID,
size = tb.size.SizeName,
sizeID = tb.SizeID,
//Quantity =
}).Distinct().ToList();
return Json(table, JsonRequestBehavior.AllowGet);
}
public JsonResult StuckDetails (int ID)
{
var table = (from tb in db.Stocks
where ID == tb.Production.ItemID
group tb by new
{
tb.Production.fabric.Colors.ColorName,
tb.size.SizeName
} into grp
select new
{
color = grp.Key.ColorName,
size = grp.Key.SizeName,
Quantity = grp.Sum(g => g.Quantity)
});
return Json(table, JsonRequestBehavior.AllowGet);
}