After reading about Custom EFContextProvider and implementing it, I am still trying to figure out what is the best way to perform server side validation and how to apply business rule before saving...Namely my questions are revolving around 2 methods that are supposed to be overridden:
protected override bool BeforeSaveEntity(EntityInfo entityInfo) { //}
protected override Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap) { // }
I am aware that docs specify that "BeforeSaveEntity method will be called for every entity before the BeforeSaveEntities method is called" once. Also, the questions I have revolve around validating/applying business rules on multiple entities that have domain specific relationships and not necessarily validating single entity's property (for that, I believe custom validation could work as explained here)
So my questions are:
- How do I return validation errors back from server? Once I apply business rules, and in case they fail how do I add validation error to one or more entities?
- How do I pass some sort of validation context so that server side code "knows" which business rules to apply? My application can add new Customer in several different places and based on app context a business rules should be applied or it should be optional. For example, if there is an explicit "Add New Customer" screen as well as "Print Check" screen which allows creating a new customer "on the fly" (in which case, more rules must be checked). This may not be desired design but it is requirement. There is few other places where customer can be created as well....On the server side though, I don't get this "context" in order to decide how to apply (and in which order) business rules...Furthermore, I cannot use logic of checking which entities I have in saveMap (in case of BeforeSaveEntities) in order to determine context since that is not deterministic (saveMap could have same entities for different app contexts)
Thanks Z...