Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up LINQ to SQL queries

Tags:

c#

sql

linq

What are the common things that we can keep in mind while writing the LINQ to SQL query for optimizing or speeding up the LINQ to SQL?.

For example, ordinarily, LINQ to SQL must translate LINQ queries to SQL every time a query executes; this involves recursing the expression tree that makes up the query in several stages. What we do is like precompiling the query using the CompiledQuery class.

like image 415
StackOrder Avatar asked Apr 18 '14 08:04

StackOrder


People also ask

Which is faster LINQ or SQL?

Sql is faster than Linq. Its simple: if I m executing a sql query directly its a one way process whereas if I m using linq, first its been converted to sql query and then its executed.

Are LINQ queries faster?

Most of the times, LINQ will be a bit slower because it introduces overhead. Do not use LINQ if you care much about performance. Use LINQ because you want shorter better readable and maintainable code.

How LINQ queries converted into SQL queries?

LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the LINQ to SQL API to request query execution. The LINQ to SQL provider then transforms the query into SQL text and delegates execution to the ADO provider.


1 Answers

There is one helpful thing about LINQ that every developer should know. It is about performance of Join vs Where.

The full discussion can be seen here why is join so much faster than where

like image 109
Mare Infinitus Avatar answered Sep 23 '22 15:09

Mare Infinitus