5

Based on other posts such as Entity Framework and DbContext - Object Tracking it would appear the simplified DBContext interface doesnt expose the to set No tracking on basic queries. A little blog showing how with Object context http://blogs.microsoft.co.il/blogs/gilf/archive/2009/02/20/disabling-change-tracking-in-entity-framework.aspx

What is a good approach to loading results via the DbContext as not tracked? How are the performance conscious doing this if using Dbcontext ? ie have base GetList method 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);
    }
Community
  • 1
  • 1
phil soady
  • 10,013
  • 4
  • 44
  • 82

1 Answers1

7

The AsNoTracking is an extension on IQueryable.

You can update your function above with:

public virtual IQueryable<T> GetList(Expression<Func<T, bool>> predicate)
    {
         return EntityDbSet.Where(predicate).AsNoTracking();
    }
Mark Oreta
  • 10,086
  • 1
  • 29
  • 35
  • Works a treat. Here i am convinced it wasnt exposed on dbset. I was looking for wrong option. thanks Mark – phil soady Oct 16 '12 at 23:00
  • Please also note: http://stackoverflow.com/questions/5502572/how-do-i-turn-off-change-tracking-at-the-dbcontext-level-in-ef-4-1-rc – phil soady Oct 17 '12 at 11:02