Mitch
Mitch

Reputation: 2551

AsNoTracking using LINQ Query syntax instead of Method syntax

I'm interested in using AsNoTracking with my LINQ select queries to improve performance. I'm using Entity Framework 5 with Code First.

However, all of my queries are written using LINQ Query syntax and all of the AsNoTracking examples are shown using the Method syntax. I'm aware that AsNoTracking was created for the Method syntax but how do I achieve the same thing with the Query syntax?

Upvotes: 18

Views: 11198

Answers (2)

qujck
qujck

Reputation: 14580

You apply AsNoTracking() to the DbSet:

var result = (
    from person in ctx.People.AsNoTracking()
    select person)
    .ToList();

Upvotes: 33

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

Query syntax is replaced with method syntax by compiler, so there is no difference at all at the end.

Upvotes: 1

Related Questions