Otis wrote:
I think the main issue is in whether or not the length of data is a business rule. Say you define the length as '100', as the business rule. If the field in the table can only hold 90 characters, your BR might succeed, but the save will fail.
You are correct that my BR might succeed, but the save would fail. The problem is that I may not even get to that point where my BR is called, because the PL setting the fields in the entity might throw an exception before the code that passes the entity to the BR for validation is even called.
That's why I have a bit of a problem with defining it as a BR, because it doesn't help much. I see the point of having rules independent of database limitations/definitions, though in this case I can't help but think that defining the length as a BR isn't that helpful.
And I certainly respect that opinion as I have seen other posts that say the same thing. Is there a suggested approach for having some "mini-validation" in the PL to test for lengths, before attempting to set the fields in the entity? Somehow, I need to avoid having an exception thrown when an entity's field length is exceeded in the PL, and ideally, not have to recode length limits manually in the PL.
I have been toying with the idea of calling some PL helper class that accepts a list of form controls and each associated entity field, and have it automatically set the maximum length of each form control. I'm just thinking there must be a better way.
Thanks!