Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. filterData linq query - EntityCommandExeceptionException error

filterData linq query - EntityCommandExeceptionException error

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharplinqregex
2 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss786
    wrote on last edited by
    #1

    Dear all, When I try to query 24 values of name parameter , api/test/name=stop,tap,app...(24 names values), I get a following EntityCommandExeceptionException error as an output response: "Message":"An error has occurred.","ExceptionMessage":"Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.","ExceptionType":"System.Data.SqlClient.SqlException

    public HttpResponseMessage get([FromUri] Query query)
    {
    var data = db.database_bd.AsQueryable();

                if (query.startDate != null)
                {
                    data = data.Where(c => c.UploadDate >= query.startDate);
                }
    
                // If any other filters are specified, return records which match any of them:
                var filteredData = new List\>();
    
                if (!string.IsNullOrEmpty(query.name))
                {
                    var ids = query.name.Split(',');
                    foreach (string i in ids)
                    {
                        filteredData.Add(data.Where(c => c.Name != null && c.Name.Contains(i)));
                    }
                }
                // If no filters passed, return all data.
                // Otherwise, combine the individual filters using the Union method
                // to return all records which match at least one filter.
                if (filteredData.Count != 0)
                {
                    data = filteredData.Aggregate(Queryable.Union);
                }
                ****if (!data.Any())** //line causing the error**
                {
                    var message = string.Format("No data was found");
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                }
    
                return Request.CreateResponse(HttpStatusCode.OK, data);
            }      
    }
    

    Do I have to assign count value to filterdata, or Is their certain threshold, to search criteria, if using the split function? Any help would be very much appreciated. Thanks in advance.

    M 1 Reply Last reply
    0
    • M miss786

      Dear all, When I try to query 24 values of name parameter , api/test/name=stop,tap,app...(24 names values), I get a following EntityCommandExeceptionException error as an output response: "Message":"An error has occurred.","ExceptionMessage":"Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.","ExceptionType":"System.Data.SqlClient.SqlException

      public HttpResponseMessage get([FromUri] Query query)
      {
      var data = db.database_bd.AsQueryable();

                  if (query.startDate != null)
                  {
                      data = data.Where(c => c.UploadDate >= query.startDate);
                  }
      
                  // If any other filters are specified, return records which match any of them:
                  var filteredData = new List\>();
      
                  if (!string.IsNullOrEmpty(query.name))
                  {
                      var ids = query.name.Split(',');
                      foreach (string i in ids)
                      {
                          filteredData.Add(data.Where(c => c.Name != null && c.Name.Contains(i)));
                      }
                  }
                  // If no filters passed, return all data.
                  // Otherwise, combine the individual filters using the Union method
                  // to return all records which match at least one filter.
                  if (filteredData.Count != 0)
                  {
                      data = filteredData.Aggregate(Queryable.Union);
                  }
                  ****if (!data.Any())** //line causing the error**
                  {
                      var message = string.Format("No data was found");
                      return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                  }
      
                  return Request.CreateResponse(HttpStatusCode.OK, data);
              }      
      }
      

      Do I have to assign count value to filterdata, or Is their certain threshold, to search criteria, if using the split function? Any help would be very much appreciated. Thanks in advance.

      M Offline
      M Offline
      miss786
      wrote on last edited by
      #2

      I have tried changing how the filterdata is added to the list, but I am still experiencing the same issue as my orginal post:

      if (!string.IsNullOrEmpty(query.name))
              {
                  var ids = query.name.Split(',');
                  foreach (string i in ids)
                  {
                      **var list = data.Where(c => c.Name != null && c.Name.Contains(i)).AsQueryable();
                      filteredData.Add(list);**
                  }
              }
      

      could someone please provide any assistance. Many thanks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups