Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Entity Framework two types of queries

What is the difference between these queries? What are their names and when should I use which?

var queryLondonCustomers = from cust in customers
                           where cust.City == "London"
                           select cust;


using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Where(b => b.Url.Contains("dotnet"))
        .ToList();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Well, they’re two entirely different queries for one thing.

But if you’re just asking about the syntax difference, the former syntax is interpreted into the latter syntax during compilation. So any two queries which differ only in the syntax (and not in the actual query functionality) are for all intents and purposes identical.

For example, this:

from cust in customers
where cust.City == "London"
select cust

Is the same as this:

customers.Where(cust => cust.City == "London")

It’s possible the compiler might produce something a little different, such as also appending a .Select() which doesn’t actually do anything interesting. But the point is that the "LINQ syntax" of the former doesn’t do anything special, it’s just a syntactically different way of expressing the latter.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading