【发布时间】:2017-11-01 14:53:49
【问题描述】:
当我到达db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(i).Value.ToString()).ToList()时
我得到以下异常:The Result of a Query Cannot be Enumerated More than Once
我尝试通过调用 ToList() 来更改 LabelComponents,就像建议的 answer 一样。
long? GroupID = db.GetGroupIDByName("PrintTest").SingleOrDefault();
ObjectResult<long?> LabelIDs = db.GetLabelIDSFromGroupingsByGroupID(GroupID.ToString());
for (int i = 0; i < LabelIDs.Count(); i++)
{
var LabelComponents = db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(i).Value.ToString()).ToList();
List<Component> Label = new List<Component>();
for(int j = 0; j < LabelComponents.Count(); j++)
{
....
....
【问题讨论】:
-
第一句的代码和你的sn-p不匹配,你确定你的实际代码中有
ToList吗? -
@DavidG var LabelComponents = db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(i).Value.ToString()).ToList();它就在那里。没有?
-
把
.ToList()放在GetLabelIDSFromGroupingsByGroupID()之后 -
您需要在 first db 调用中使用
ToList,您将多次枚举LabelIDs值。
标签: c# sql asp.net-mvc stored-procedures