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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to improve nested linq query

how to improve nested linq query

Scheduled Pinned Locked Moved ASP.NET
databaselinqcsharpjsonhelp
1 Posts 1 Posters 2 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

    I would like to be able to call string tag1 & tag2 with multiple values, such as Api/test?tag1=123,456,789&tag2=987,654 However, the below contain function only allows me to call 45 values for each tag1 & tag2, anything more than 45 string values used to search tag1 & tag2, the code throws a nested query error: "$id":"1","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. I tried adding toList() to my tag1 method, but I keep getting syntax error: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?) any further advice, would be very much appreciated. Thank you.

    IQueryable Data = null;

                if (!string.IsNullOrEmpty(query.tag2))
                {                  
                    var ids = query.tag2.Split(',');
    
                    var dataMatchingTags = db.database\_BCs.Where(c => ids.Contains(c.TAG2));
    
                    if (Data == null)
                        Data = dataMatchingTags;
                    else
                        Data = Data.Union(dataMatchingTags);
                }
    
                if (!string.IsNullOrEmpty(query.tag1))
                {
                    var ids = query.tag1.Split(',');
    
                    var dataMatchingTags = db.database\_BCs.Where(c => ids.Contains(c.TAG1));
    
                    if (Data == null)
                        Data = dataMatchingTags;
                    else
                        **Data = Data.Union(dataMatchingTags).ToList();**
                }
    
                if (Data == null) // If no tags is being queried, apply filters to the whole set of products
                    Data = db.database\_BCs;
    
                if (query.dl\_type != null)
                {
                    Data = Data.Where(c => c.Type == query.dl\_type);
                }
    			
    	  **var data = Data.ToList();**
    
                if (!data.Any())
                {
                    var message = string.Format("No data found");
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                }
    
    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