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
  • 868,454
  • 176
  • 1,908
  • 1,964
ojek
  • 9,680
  • 21
  • 71
  • 110

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
  • 66,820
  • 29
  • 157
  • 232