DBContext DBSet query and lack of tracking

Based on other messages, such as Entity Framework and DbContext - object tracking, it would seem that the simplified DBContext interface does not provide No tracking for basic queries. A small blog showing how with the object context http://blogs.microsoft.co.il/blogs/gilf/archive/2009/02/20/disabling-change-tracking-in-entity-framework.aspx

What good approach to loading results through DbContext is not monitored? How does conscious performance do this when using Dbcontext? those. have a basic GetList method that I would like to improve for performance reasons.

public DbSet<T> EntityDbSet { get { return _context.Set<T>(); } } public virtual IQueryable<T> GetList(Expression<Func<T, bool>> predicate) { return EntityDbSet.Where(predicate); } 
+4
source share
1 answer

AsNoTracking is an extension of IQueryable.

You can update your function above:

 public virtual IQueryable<T> GetList(Expression<Func<T, bool>> predicate) { return EntityDbSet.Where(predicate).AsNoTracking(); } 
+6
source

Source: https://habr.com/ru/post/1440104/


All Articles