Print Page | Close Window

Stop EntityManager from refreshing entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3232
Printed Date: 23-Apr-2025 at 8:51am


Topic: Stop EntityManager from refreshing entities
Posted By: katit
Subject: Stop EntityManager from refreshing entities
Date Posted: 24-Jan-2012 at 2:16pm
I'm not sure if it is EF or DevForce behavior (I assume it is EF) but would like to know if I can stop it.
 
I'm sharing same model on server between my Silverlight project and using it on server for WCF services. In case of services - all calls are in and out and have very small scope..
 
Here is example picture of what I see in Profiler:
 
 
Basically, I persist my entities and EF automatically refereshes it's state - loading keys, etc.
 
But I KNOW that this is my last call and service will exit after that. How can I control if it's even possible so EF doesn't refresh itself and doesn't issue those additional selects against database? Trying to optimize as much as I can
 



Replies:
Posted By: sbelini
Date Posted: 24-Jan-2012 at 3:01pm
Hi katit,
 
You could use EntityTypesExcludedFromPostSaveRefetch:
 
SaveOptions options = new SaveOptions();
options.EntityTypesExcludedFromPostSaveRefetch = new Type[] {mySavedEntity.GetType()};
mgr.SaveChangesAsync(options, saveOp => {
  if (saveOp.CompletedSuccessfully) {
    // ...
  }
});
 
While the PKs and FKs will be resolved, the entities' EntityState will not be updated (although it shoudn't be an issue since you are exitting).
 
Regards,
   Silvio.


Posted By: katit
Date Posted: 25-Jan-2012 at 2:39pm
Thanks! It worked. You had typo, line should read:
 
options.EntityTypesExcludedFromPostSaveRefetch = new Type[] {mySavedEntity.GetType()};


Posted By: sbelini
Date Posted: 26-Jan-2012 at 10:05am
Thanks!
 
Fixed.



Print Page | Close Window