Prevent entity from saving to database upon call SaveChanges

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
djuj
Posts: 4
Joined: Thu 25 Jun 2009 18:45

Prevent entity from saving to database upon call SaveChanges

Post by djuj » Sun 01 Nov 2009 04:19

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();

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 02 Nov 2009 13:31

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.

Post Reply