0

我已经到了 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()。

请帮忙!非常感激!

4

1 回答 1

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"
               };
于 2010-06-09T19:48:36.223 回答