In our previous post in this series we had a look at how to optimize query execution with the help of parameterized queries. Today we will briefly look at what actually happens ‘behind the curtains’ when a LINQ query is executed and you get back the results.
As you already know LINQ can be used to query various data sources like in-memory objects, XML or databases,which is of particular interest to us. Consider the following example where we query for all employees who are born in the same month as today i.e. in the month of July.
Telerik OpenAccess ORM performs several such translations in order to improve the performance of the LINQ queries. Consider the following example where we query for all employees whose country name ends with ‘ia’.
It gets translated to the following select statement
Notice how the String.EndsWith call is translated to a SQL ‘LIKE’ pattern. Various String methods like Contains, EndsWith, Equals are translated to SQL specific LIKE patterns.
It is also worth mentioning that all these SQL translations are backend specific. So a call to DateTime.Month would translate to MONTH (date) on MS SqlServer and for Firebird it would generate a call to EXTRACT (MONTH FROM datetime).
Keep an eye out for more such interesting LINQ tips and tricks, wishing you happy programming with Telerik OpenAccess ORM.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.