我有一个快速的问题。我有一个名为Categories的表,我想列为SelectListItem
。到目前为止,我尝试使用以下代码:
_context.Categories.ToList();
_context.Categories.AsIEnumerable();
但没有运气。
我如何查询我的表IEnumerable
?
试试这个代码:
var selectListItems= _context.Categories
.Select(i=> new SelectListItem {
Value=i.Id.ToString(),
Text=i.Name
}).ToList(); // or .ToArray() it will be a little more sufficient As enumerable
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句