The result of a query cannot be enumerated more than once

后端 未结 3 1619
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 06:53

I am using the entity framework (ef) and am getting the following error:

\"The result of a query cannot be enumerated more than once.\".

相关标签:
3条回答
  • 2020-11-27 07:22

    if you getting this type of error so I suggest you used to stored proc data as usual list then binding the other controls because I also get this error so I solved it like this ex:-

    repeater.DataSource = data.SPBinsReport().Tolist();
    repeater.DataBind();
    

    try like this

    0 讨论(0)
  • 2020-11-27 07:27

    Try replacing this

    var query = context.Search(id, searchText);
    

    with

    var query = context.Search(id, searchText).tolist();
    

    and everything will work well.

    0 讨论(0)
  • 2020-11-27 07:30

    Try explicitly enumerating the results by calling ToList().

    Change

    foreach (var item in query)
    

    to

    foreach (var item in query.ToList())
    
    0 讨论(0)
提交回复
热议问题