When I get to db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(i).Value.ToString()).ToList()
当我到达db.GetLabelComponentsByLabelID(LabelIDs.ElementAt(I).Value.ToString()).ToList()
I get the following exception: The Result of a Query Cannot be Enumerated More than Once
我得到以下异常:查询的结果不能被枚举不止一次
I tried to change LabelComponents by calling ToList()
like this answer suggested.
我试图通过调用ToList()来更改标签组件,就像这个答案所建议的那样。
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++)
{
....
....
1 个解决方案
#1
1
You need ToList
on the first db call because you are enumerating the LabelIDs
value multiple times. LabelIDs.Count
runs the query the first time, then LabelIDs.ElementAt
runs it again later on.
您需要在第一个db调用中列出,因为您要多次枚举LabelIDs值。LabelIDs。Count第一次运行查询,然后运行LabelIDs。ElementAt稍后再次运行它。
#1
1
You need ToList
on the first db call because you are enumerating the LabelIDs
value multiple times. LabelIDs.Count
runs the query the first time, then LabelIDs.ElementAt
runs it again later on.
您需要在第一个db调用中列出,因为您要多次枚举LabelIDs值。LabelIDs。Count第一次运行查询,然后运行LabelIDs。ElementAt稍后再次运行它。