Print Page | Close Window

Customizing SaveChanges()

Printed From: IdeaBlade
Category: Breeze
Forum Name: Community Forum
Forum Discription: Build rich JavaScript apps using techniques you already know
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3661
Printed Date: 19-Jan-2021 at 2:53pm


Topic: Customizing SaveChanges()
Posted By: pawel
Subject: Customizing SaveChanges()
Date 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



Replies:
Posted By: jtraband
Date 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();




Print Page | Close Window