通常情况下,.Key属性设置为什么?
在下面的示例中,密钥似乎是空白的。至少它不是预期的vendorName。
我想当我循环时,我可以在项目上获得vendorName,但为什么它不在组级别,或者如果它在那里,它在哪里?
int poItemsCount = 0;
foreach (var item in linqQuery)
{
poItemsCount++;
webPOInfo info = new webPOInfo(item.qVendorName, item.qSku, item.qTransID, item.qSize, item.qQty);
lstPOInfo.Add(info);
}
//loop through each vendor name group
var linqGroups = lstPOInfo.GroupBy(x => x.VendorName);
循环浏览结果:
foreach (var group in linqGroups)
{
//for each group, we need to create a PO header
Logging.logMessage("Creating a PO for Vendor: " + group.Key, trcProgramName, trcProgGuid, trcCorrGuid, trcKey, "4201", null);
...etc
}
跟踪显示:
为供应商创建采购订单:
分组后必须创建一个新对象。
lstPOInfo.GroupBy(x => x.VendorName, (key, webPoInfoCollection) => new { Key = key, objectCollection = webPoInfoCollection });
以下是如何循环浏览组数据。
foreach (var groupObj in linqGroups)
{
//for each group, we need to create a PO header
Logging.logMessage("Creating a PO for Vendor: " + groupObj.Key, trcProgramName, trcProgGuid, trcCorrGuid, trcKey, "4201", null);
foreach (var webPo in groupObj.objectCollection)
{
...etc
}
...etc
}