This is a migrated thread and some comments may be shown as answers.

Grid Read Error: The Result of the Query cannot be enumerated more than once Error

3 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 05 Dec 2013, 05:45 PM
I have a  Grid read method that throws this error on the ToDataSourceResult line at the bottom.   
The context.Search_All method is a SQL Stored Procedure in the context object.    

Any suggestions?
             
  public ActionResult Search_Read([DataSourceRequest]DataSourceRequest request, SearchInputModel input)
        {
            var username = _identityService.UserID;
            using (var context = new eEntities.eWJB())
            {
                context.Configuration.ProxyCreationEnabled = false;

                
                IQueryable search = context.Search_All("a", "b", "c", "d", "1", true)
              .AsQueryable()    
              .Select( item => new SearchResultModel
                                      {
                                          ID1 = item.ID1,
                                          ID2 = item.ID2,
                                          1D3 = item.ID3,
                                          Name= item.Name,
                                          Name2= item.Name2});
                var result = search.ToDataSourceResult(request);        <--- Error Here
          
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
          

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Dec 2013, 05:48 AM
Hello,

Please use ToList() in place of IQueryable.

var search = context.Search_All("a", "b", "c", "d", "1", true)
             .ToList()  
             .Select( item => new SearchResultModel
                                     {
                                         ID1 = item.ID1,
                                         ID2 = item.ID2,
                                         1D3 = item.ID3,
                                         Name= item.Name,
                                         Name2= item.Name2}).ToList();

//OR Name2= item.Name2});



Note : We can not usedc cached query more than once in linq.


Thanks,
Jayesh Goyani
0
Bob
Top achievements
Rank 1
answered on 06 Dec 2013, 03:23 PM
Thanks - I cannot get the JSON passed via jquery to the Search/Read Controller

var dataSource = new kendo.data.DataSource({    // create datasource
        transport: {
            read:  {
                url: "/Search/Search_Read",
                dataType: "json",
                data: data,
                contentType: "application/json; charset=utf-8"

            }
        }
This code hits the correct controller and the data element is correctly formatted JSON (I have tested it)...  But when this hits the controller the data is null.

Any suggestions?
0
Daniel
Telerik team
answered on 09 Dec 2013, 02:30 PM
Hello,

You should use a POST request when sending JSON:
read:  {
    url: "/Search/Search_Read",
    type: "POST",
    dataType: "json",
    data: data,
    contentType: "application/json; charset=utf-8"
}


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Bob
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or