The essential difference between Entity SQL and LINQ to Entity

Source: Internet
Author: User
Tags foreach

It can be seen that the final transfer to the command tree and then converted to the database of T-SQL statements, there is little difference in nature, but sometimes the execution of special query statements is somewhat different, because the Entity SQL T-statement is our own definition, and LINQ to Entity the last converted T-SQL statement was converted by the entity engine, and sometimes when we use SQL Server Profiler to detect executed SQL statements, the SQL executed by LINQ to entity often makes it difficult for us to understand, so there is a need for some queries/modifications/ If you find that execution is inefficient when you perform an update, consider using Entity SQL to execute the SQL statement, and then post a dot code below:

1.LINQ to Entity

String city = "London";
using (entities entities = new entities ())
{
var query = from C in entities. Customers
where c.address.city = = City
select C;
foreach (Customers C in Query)
     Console.WriteLine (c.companyname);
}

2.Entity SQL (Note SQL statement OH)

String city = "London";
using (entities entities = new entities ())
{
     objectquery<customers> query = entities. Createquery<customers> (
         "select VALUE C from Customers as C WHERE c.address.city = @city", New objectparameter< c14/> ("city")
;
foreach (Customers C in Query)
     Console.WriteLine (c.companyname);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.