Page 1 of 1

Prevent entity from saving to database upon call SaveChanges

Posted: Sun 01 Nov 2009 04:19
by djuj
Is there a way to override entity framework behavior when calling SaveChanges on DBModelContext?


In following example, I would like to prevent changes in customer entity to reflect in database, but want to allow changes to products be reflected in db.

var customer = dbmodelctx.customer.where().select(c => c).first();
customer.status = "something";

var products = dbmodelctx.products.select(p=>p);
foreach (var p in products)
{
if (customer.status == "something") p.status='anything';
}
dbmodelctx.savechanges();

Posted: Mon 02 Nov 2009 13:31
by AndreyR
You can try to use Refresh(RefreshMode.StoreWins, customer). After this call the customer will obtain current values from database (extra database call), and the state of it will become Unchanged, so it will not participate in SaveChanges.