![](/img/trans.png)
[英]The result of a query cannot be enumerated more than once when using stored procedure
[英]The Result of a Query Cannot be Enumerated More than Once (C#) (Entity Framework) (Stored Procedure)
当我到达db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(i).Value.ToString()).ToList()
我收到以下异常: The Result of a Query Cannot be Enumerated More than Once
我试图通过像这个答案建议的那样调用ToList()
来更改 LabelComponents。
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++)
{
....
....
您在第一次db 调用时需要ToList
,因为您要多次枚举LabelIDs
值。 LabelIDs.Count
第一次运行查询,然后LabelIDs.ElementAt
稍后再次运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.