Home  /  Questions  /  Question

108   96.7
Aug 03, 2011

Business Rules in project

I know that the business rules belong in the Business Layer but I need help understanding when and why they are happening in the example. The example seems to set business rules on an object in the Business Layer when mapping data being retrieved from the database. I don't see the relevance in that and what the purpose is in setting or validating data retrieved from the database. How does that help?


588   99.9
Aug 08, 2011
Dennis, it seems you are a little confused as to how the Business Rules work in their framework.  It is a little complicated, but it's not validating data from the database.  It's validating data when it comes into the service layer from the presentation layer.

The way it works is, when a new business object is created, all the rules for that class populate a collection of rules, that then wait to be validated in the service layer.

When the object is passed into an Insert or Update method, for example, the Validate() method is called which iterates over the rules collection and compares the rule with the property value.  If the rule passes, then it returns True, otherwise it returns False.  Then it passes a message back up to the presentation layer.

If you look at the WCF service implementation class and go into any of the Set[class name] methods, you'll see the [object].Validate() method called in an IF statement.  Inside the IF statement there's a FOREACH statement that iterates over the ValidateErrors collection.  This is where the validation occurs.

I hope this helps clear this up.
 1 comment
Thank you for the response. I finally figured it out. What doesn't make sense to me is that it does the validation on an update/insert. The part that is confusing is that on an update it makes another trip to the database to retrieve the data and then does the update which then does the validation. You already have the data in an update so why would you make another trip to the database and then modify that object and then do your database update? 2 trips for an update? Thanks dennis --- Dennis Tucker  Aug 09, 2011