Linq Max() and Any() generates strages SQL

Thread is closed for posting
1 posts, 0 answers
  1. Rolf
    Rolf avatar
    1 posts
    Member since:
    Dec 2014

    Posted 07 Mar 2016 Link to this post

    Dear all

    While using the DataAccess framework we're using the following linq statements:

    context.TableName.Max(t => t.ID) and context.TableName.Any()

    After profiling with SQL Profiler, we found out, that Telerik generates very strage SQL like:

    SELECT COUNT(1) FROM ( SELECT a.[ID] AS COL1, a.[column2] AS COL2, a.[column3] AS COL3, a.[column4] AS COL4, a.[column5] AS COL5, [column6] AS COL6, a.[column7] AS COL7, a.[column8] AS COL8, a.[column9] AS COL9, a.[column10] AS COL10, a.[column11] AS COL11, a.[column12] AS COL12, a.[column13] AS COL13, ..., a.[column33] AS COL33 FROM [TableName] a  ) AS TMP_COUNT

    This SQL query takes in database with about 120'000 entries up to 10 seconds while the following query (which we would expect when using context.TableName.Max(t => t.ID) takes some milliseconds:

    SELECT MAX(ID) from [TableName]

    Why is the Telerik DataAccess framework generating such queries which are performing so bad? And how can be avoid using this query? Only by writing our own SQL?



Back to Top