简体   繁体   中英

Which where clauses in LINQ are converted to where clauses in a database query

I've just started reading about LINQ and there is one thing that's been bugging me. LINQ turns a LINQ query into a corresponding SQL query to a database server. Since I doubt that LINQ can convert any code to an SQL statement I must assume that there are some limits here.

Since I want to have the query that is sent to the server as restrictive as possible, what can LINQ turn into SQL and what can't LINQ turn into SQL?

For example where employee.name == "Test" looks pretty trivial to convert, but what about where isEven(employee.number) ? Or something more complex?

Here is the MSDN page detailing which methods LINQ to SQL supports.

You will not be able to use your own method calls inside of the expression tree, as LINQ to SQL does not understand how to convert the methods into SQL.

Some ORMs (eg NHibernate) allow you to define your own generators for generating SQL (HQL in NHibernates case) for your own methods, I do not believe L2S supports this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM