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

asp.net-mvc c# entity-framework

Question

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?

1
7
3/4/2013 7:17:39 PM

Accepted Answer

I think you can use AsNoTracking and for Transactions use Detach

Youcontext.YourEntities.AsNoTracking().Where);

or use

Youcontext.Transactions.Detach(obj);
9
3/4/2013 7:21:16 PM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow