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. General Programming
  3. LINQ
  4. Count taking too long in nested query

Count taking too long in nested query

Scheduled Pinned Locked Moved LINQ
2 Posts 2 Posters 0 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.
  • T Offline
    T Offline
    the_jat
    wrote on last edited by
    #1

    I am trying to retreive an entire object(including related/nested objects -- there are 2 such collections in the object) using the Include Method(Eager-Loading) i am calling this object as "EveryThing" and 2 of its contained collections as A and B. i also need to retreive "EveryThing" based on wether a '=' or LIKE condition is satisfied in A. i.e. i am checking something like "EveryThing".A.FirstName=="abc", then retrieve "EveryThing" and its two collections. The query is like:

    string searchQuery1 = @"SELECT VALUE TOP(20) sSet FROM EveryThing as sSet where sSet.SPERID LIKE '%1020%' AND COUNT(SELECT VALUE A.ADR FROM sSet.SADDR AS A WHERE A.ADR LIKE '%BOR%') >= 0";

    The query executes fine and returns prefect results, the problem is that it takes around 6-7 minutes to retrieve 20 results. if on the other hand we use EXISTS, the query takes only a fraction of second to execute. I know that exists works, but what is wrong with COUNT? , also is there some other way to acomplish the same thing? Also is there a tool that can help build Entity SQL queries, do the typechecking and other stuff?

    T 1 Reply Last reply
    0
    • T the_jat

      I am trying to retreive an entire object(including related/nested objects -- there are 2 such collections in the object) using the Include Method(Eager-Loading) i am calling this object as "EveryThing" and 2 of its contained collections as A and B. i also need to retreive "EveryThing" based on wether a '=' or LIKE condition is satisfied in A. i.e. i am checking something like "EveryThing".A.FirstName=="abc", then retrieve "EveryThing" and its two collections. The query is like:

      string searchQuery1 = @"SELECT VALUE TOP(20) sSet FROM EveryThing as sSet where sSet.SPERID LIKE '%1020%' AND COUNT(SELECT VALUE A.ADR FROM sSet.SADDR AS A WHERE A.ADR LIKE '%BOR%') >= 0";

      The query executes fine and returns prefect results, the problem is that it takes around 6-7 minutes to retrieve 20 results. if on the other hand we use EXISTS, the query takes only a fraction of second to execute. I know that exists works, but what is wrong with COUNT? , also is there some other way to acomplish the same thing? Also is there a tool that can help build Entity SQL queries, do the typechecking and other stuff?

      T Offline
      T Offline
      Thanigainathan S
      wrote on last edited by
      #2

      Hi, Your query should be like SELECT VALUE TOP(20) sSet FROM EveryThing as sSet where sSet.SPERID LIKE '%1020%' AND exists(SELECT VALUE COUNT(A.ADR) FROM sSet.SADDR AS A WHERE A.ADR LIKE '%BOR%')"; If you put the coutn keywork outside then for each sset all the "A" records will be fetched . This will impact performace. Thanks, Thani

      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