7

I have something like this:

var dbTransactions = context.Transactions.Where(t => t.Date >= yesterday).Select(t => t).ToList();

Now, i would like to remove objects from dbTransactions list, but not from the actual database. Later on i am calling context.SaveChanges() and if i would do that, it would erase rows from my db. How can i disable changes tracking for dbTransactions?

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
ojek
  • 8,947
  • 19
  • 68
  • 108

2 Answers2

9

I think you can use AsNoTracking and for Transactions use Detach

Youcontext.YourEntities.AsNoTracking().Where);

or use

Youcontext.Transactions.Detach(obj);
  • 1
    Is there anything like a `[NoTracking]` attribute to use for POCO entities? How should we mark POCO entities (in our case lookup entities) as no-tracking?! – orad Jun 26 '14 at 01:32
0

Remove those entities from the context using Detach():

context.Transactions.Detach(obj);

so clearly you will have to recover that list - but then just iterate through it and detach them.

Mike Perrenoud
  • 64,877
  • 28
  • 152
  • 226