Reputation: 2551
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
Reputation: 14580
You apply AsNoTracking()
to the DbSet
:
var result = (
from person in ctx.People.AsNoTracking()
select person)
.ToList();
Upvotes: 33
Reputation: 125630
Query syntax is replaced with method syntax by compiler, so there is no difference at all at the end.
Upvotes: 1