我已经到了Linq绳子的尽头。需要你的帮助!
首先是我的表结构(所有linq到sql对象):
InventoryItems
-ID
-AmtInStock
IventoryKits
-ID
InventoryKits_to_InventoryItems
-InventoryItemID
-InventoryKitID
所以我需要进行如下投影
var q2=from k in GetAllKits()//returns IQueryable<InventoryKit>
select new VMPublication()//ViewModel Object
{
ID = k.ID,
Name = k.Name,
WebAmountInStock = ,//need to get the Min() AmtInStock from InventoryItems here
ItemCode = k.ItemCode,
WebAmountOrdered = k.AmtOrdered.ToString(),
WebReminderAmount = "",
WebAmountWarning="",
Type = "Kit"
};
我不知道如何在该查询中获得InventoryItem的AmtInStock的Min()。
请帮忙!非常赞赏!
答案 0 :(得分:0)
我猜你的关联名字,但尝试类似:
var q2=from k in GetAllKits()//returns IQueryable<InventoryKit>
select new VMPublication()//ViewModel Object
{
ID = k.ID,
Name = k.Name,
WebAmountInStock = (from i in k.InventoryKits_to_InventoryItems
select i.InventoryItem.AmtInStock).Min(),
ItemCode = k.ItemCode,
WebAmountOrdered = k.AmtOrdered.ToString(),
WebReminderAmount = "",
WebAmountWarning="",
Type = "Kit"
};