Is there a way to remove the change tracking mechanism for a single object?

I have something like this:

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

Now I would like to remove the objects from the dbTransactions list, but not from the real database. Later I call context.SaveChanges() , and if I did this, it would delete the lines from my db. How to disable change tracking for dbTransactions ?

+7
source share
2 answers

I think you can use AsNoTracking and use Detach for transactions

 Youcontext.YourEntities.AsNoTracking().Where); 

or use

 Youcontext.Transactions.Detach(obj); 
+9
source

Remove these objects from the context using Detach() :

 context.Transactions.Detach(obj); 

so you will need to restore this list, but then just go through it and disconnect them.

0
source

All Articles