【发布时间】:2015-04-04 19:30:51
【问题描述】:
我正在尝试将foreach 循环数据集合存储在循环之外以供以后使用。
考虑以下foreach 循环。
IList<DetailViewModel> storeAllLoopItems = new List<DetailViewModel>();
foreach (var item in _listOfItems)
{
var items =
(from a in context.Employee
join b in context.Orders on a.Id equals b.Id
join d in context.Notes on a.Id equals d.Id
where a.Id == item.id
select new DetailViewModel
{
Name = b.LegalName,
Abbrev = c.Abbrev,
TaxAmount = a.Amount,
}).ToList();
storeAllLoopItems.Add(items); //<<<ERROR
}
错误:
最好的重载方法匹配 'System.Collections.Generic.List.Add(DetailViewModel)' 有一些无效的参数
无法从“System.Collections.Generic.List”转换 到'DetailViewModel'
【问题讨论】:
标签: c# linq linq-to-sql collections