Linq SQL clause performance RRS feed

  • Question

      • db.MyTables.Count(a=> a.Id > 100)
      • (from a in db.MyTables where a.Id > 100 select a).count()

    Am I right in thing that the query in 1. retrieves all the data and then applies the function or is it clever enough to build the query that would be generated in 2.?


    Friday, September 14, 2012 11:17 PM


  • Hi RobC00;

    The two queries will produce the same T-SQL query that is sent to the SQL server. The code snippet shows what the T-SQL query looks like.

    SELECT COUNT(*) AS [value]
    FROM [MyTables] AS [t0]
    WHERE [t0].[Id] > @p0


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, September 15, 2012 2:32 AM