New Posts New Posts RSS Feed: Customizing SaveChanges()
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Customizing SaveChanges()

 Post Reply Post Reply
Author
pawel View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2012
Posts: 12
Post Options Post Options   Quote pawel Quote  Post ReplyReply Direct Link To This Post Topic: Customizing SaveChanges()
    Posted: 25-Sep-2012 at 8:28am
I would like to force some restrictions during data modifications. 
Instead of simple return _contextProvider.SaveChanges(saveBundle); I need more control during/before save.
How can I execute custom logic during save?

/Pawel
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 11:51am
This is actually supported in 0.57 ( and higher) versions.  We are in the process of documenting it now and will probably complete the documentation before the end of the week.

 But for now, the basic idea is to subclass the EFContextProvider and override either or both of the following methods
1) BeforeSaveEntity
2) BeforeSaveEntities

A simple scaffolding is shown below. 

 public class NorthwindContextProvider: EFContextProvider<NorthwindIBContext_CF>  {  

    public override bool BeforeSaveEntity(EntityInfo entityInfo) {
      return true;
    }

    public override Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap) {
      return saveMap;
    }
     
  }

  public class NorthwindIBModelController : ApiController {

    NorthwindContextProvider ContextProvider = new NorthwindContextProvider();

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down