New Posts New Posts RSS Feed: Stop EntityManager from refreshing entities
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Stop EntityManager from refreshing entities

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: Stop EntityManager from refreshing entities
    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
 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.


Edited by sbelini - 26-Jan-2012 at 10:05am
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jan-2012 at 2:39pm
Thanks! It worked. You had typo, line should read:
 
options.EntityTypesExcludedFromPostSaveRefetch = new Type[] {mySavedEntity.GetType()};
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jan-2012 at 10:05am
Thanks!
 
Fixed.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down