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
?
I think you can use AsNoTracking and for Transactions use Detach
Youcontext.YourEntities.AsNoTracking().Where);
or use
Youcontext.Transactions.Detach(obj);
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.