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. Very slow linq preformance

Very slow linq preformance

Scheduled Pinned Locked Moved LINQ
databasehelpcsharpcsssql-server
4 Posts 3 Posters 3 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.
  • W Offline
    W Offline
    willempipi
    wrote on last edited by
    #1

    Hi, I'm working for the first time with linq on a new project. I've made a few queries now, that are quite simple. They are running very fast, but, for my last query i had to do some more complex things(5 joins) and now the preformance is really really bad. It takes more than a minute to retreive 400 records(and it often gives time-outs). At first i thought it might be that the query was wrong. So i copied the query that was excuted in debug mode and ran it directly on the SQL Server using SQL Management studio. This excuted in less than a second, so the problem is not the query. Then i thought it might be that the objects that are used to join the tables together where very heavy for the application. So i moved my complete query to a stored procedure, and used linq to only excute the stored procedure, witch makes linq kind of obsolete. This gave exactly the same behaviour, the stored procedure's execution time is over a minute and often ends up in a time out, while when i excute the stored procedure directly on the sql server the excution time is less than a second. I've searched google for others with the same problem, but i cannot find anyone with the same problem. Please help me, i see the advantages of linq but with these kind of problems i think i have to switch to something different than linq. Few things, i don't know if it makes a difference: - I'm using .dbml datacontext files - The joins i make in the query are not described in this datacontext. The linq query:

    var externeuitvoeringen =
    from euv in ((UitvoeringenDataContext)_DataContext).tblExternUitvoerings

        join join\_brs in ((UitvoeringenDataContext)\_DataContext).tblBrandstofs
        on euv.lng\_euv\_brs\_ID equals join\_brs.lng\_brs\_ID
        into brs\_temp
        from brs in brs\_temp.DefaultIfEmpty()
    
        join join\_adr in ((UitvoeringenDataContext)\_DataContext).tblAandrijvings
        on euv.lng\_euv\_adr\_ID equals join\_adr.lng\_adr\_ID
        into adr\_temp
        from adr in adr\_temp.DefaultIfEmpty()
    
        join join\_vsn in ((UitvoeringenDataContext)\_DataContext).tblVersnellings
        on euv.lng\_euv\_vsn\_ID equals join\_vsn.lng\_vsn\_ID
        into vsn\_temp
        from vsn in vsn\_temp.DefaultIfEmpty()
    
        join join\_eku in ((UitvoeringenDataContext)\_DataContext).tblExternKoppelUitvs
        on euv.str\_euv\_ID equals join\_eku.str\_eku\_euv\_ID
        into euk\_temp
        from euk in euk\_temp.DefaultIfEmpty()
    
        join join\_euh in ((UitvoeringenDataContext)\_DataContext).tblExt
    
    W 1 Reply Last reply
    0
    • W willempipi

      Hi, I'm working for the first time with linq on a new project. I've made a few queries now, that are quite simple. They are running very fast, but, for my last query i had to do some more complex things(5 joins) and now the preformance is really really bad. It takes more than a minute to retreive 400 records(and it often gives time-outs). At first i thought it might be that the query was wrong. So i copied the query that was excuted in debug mode and ran it directly on the SQL Server using SQL Management studio. This excuted in less than a second, so the problem is not the query. Then i thought it might be that the objects that are used to join the tables together where very heavy for the application. So i moved my complete query to a stored procedure, and used linq to only excute the stored procedure, witch makes linq kind of obsolete. This gave exactly the same behaviour, the stored procedure's execution time is over a minute and often ends up in a time out, while when i excute the stored procedure directly on the sql server the excution time is less than a second. I've searched google for others with the same problem, but i cannot find anyone with the same problem. Please help me, i see the advantages of linq but with these kind of problems i think i have to switch to something different than linq. Few things, i don't know if it makes a difference: - I'm using .dbml datacontext files - The joins i make in the query are not described in this datacontext. The linq query:

      var externeuitvoeringen =
      from euv in ((UitvoeringenDataContext)_DataContext).tblExternUitvoerings

          join join\_brs in ((UitvoeringenDataContext)\_DataContext).tblBrandstofs
          on euv.lng\_euv\_brs\_ID equals join\_brs.lng\_brs\_ID
          into brs\_temp
          from brs in brs\_temp.DefaultIfEmpty()
      
          join join\_adr in ((UitvoeringenDataContext)\_DataContext).tblAandrijvings
          on euv.lng\_euv\_adr\_ID equals join\_adr.lng\_adr\_ID
          into adr\_temp
          from adr in adr\_temp.DefaultIfEmpty()
      
          join join\_vsn in ((UitvoeringenDataContext)\_DataContext).tblVersnellings
          on euv.lng\_euv\_vsn\_ID equals join\_vsn.lng\_vsn\_ID
          into vsn\_temp
          from vsn in vsn\_temp.DefaultIfEmpty()
      
          join join\_eku in ((UitvoeringenDataContext)\_DataContext).tblExternKoppelUitvs
          on euv.str\_euv\_ID equals join\_eku.str\_eku\_euv\_ID
          into euk\_temp
          from euk in euk\_temp.DefaultIfEmpty()
      
          join join\_euh in ((UitvoeringenDataContext)\_DataContext).tblExt
      
      W Offline
      W Offline
      willempipi
      wrote on last edited by
      #2

      After playing around with this problem i notest that the base table doesn't have a primary key, after changing this the query excuted as fast as directly on the server. Also setting some indexes improved the speed. Why this should make a difference is a mystery to me...

      D N 2 Replies Last reply
      0
      • W willempipi

        After playing around with this problem i notest that the base table doesn't have a primary key, after changing this the query excuted as fast as directly on the server. Also setting some indexes improved the speed. Why this should make a difference is a mystery to me...

        D Offline
        D Offline
        Dan Mos
        wrote on last edited by
        #3

        willempipi wrote:

        Also setting some indexes improved the speed. Why this should make a difference is a mystery to me...

        That's the purpose of indexes: to speed up serach. As a side note an index slows down inserts and updates but in a more than acceptable manner. An index is like the key in a dictionary<key,value>. So it speeds up a lot the search.

        1 Reply Last reply
        0
        • W willempipi

          After playing around with this problem i notest that the base table doesn't have a primary key, after changing this the query excuted as fast as directly on the server. Also setting some indexes improved the speed. Why this should make a difference is a mystery to me...

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          There also other ways to speed up your queries, maybe this will help Entity Framework Performance[^]


          I know the language. I've read a book. - _Madmatt

          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