【发布时间】:2017-11-19 14:49:58
【问题描述】:
我正在使用我的 ProductViewModel 中的产品填充部分视图。当模型回来时,我们有......
var viewModel = _productAgent.GetProductsByCatalog(catalogId);
viewModel 是 ProductViewModel 的集合
我正在使用 linq 将集合的大小限制为前 10 个产品 orderby createDate desc 像这样...
var newList = (from p in viewModel
//from pf in p.DomainObjectFields
select p).Distinct().OrderByDescending(d => d.CreateDate).Take(10);
我尝试加载部分...
return PartialView("_ProductGrid", viewModel);
问题是 newList 是 IEnumerable 它需要是一个集合,我不知道如何转换它或者我是否采取了正确的方法。
【问题讨论】:
标签: c# linq collections type-conversion