Partial Classes & Validation

Posts   
 
    
BringerOD
User
Posts: 70
Joined: 15-Jul-2006
# Posted on: 15-Jul-2006 18:21:55   

I am new to this software and am very excited about using it.

I have read most of the documentation and experimented with the generation of the some code, but am having some problems still. I was hoping some of the local experts could assist me further.

1) No matter what I do I cannot get the software to generated partial classes. I am using the VB.NET generation if that matters. I see no where in the options that sets this. I know you can do it, because the demo example generated code has it in there, but for some reason I cannot find how to turn this feature on. Maybe it does not work in the demo.

2)Validation, currently I code my business layer by hand, which is very time consuming, but allows a lot of control obviously. Here is what we do:

a.We have made a series of classes that handle all sorts of types of data.

  i.EmailFieldValidator:  This validates if it’s a good email,  it can check the domain and ping it, etc.

  ii.LongValidator:  Has settings to check if required,  if you have a minimum number value or maximum etc.

  iii.I can go on but we have class for every type of field in our system.

b.Then what we do is each business object maintains a collection of violations. These violations can be updated from the validator’s or in a custom manner. Anywhere in our code we can add a validation error to the business objects collection, and if the person using this object tries to save, the action will not be performed and the validation information is shown to the user. This makes it easy to right the presentation layers in a consistent manner. Also this information is localized. Here is the process.

  i.On creation of an object:  We initialize the validation objects and set the properties we want for each.  i.e.  Is this required,  is there a minimum value, should we check and ping the domain, etc.  For each business object.  Its like setting database constraints but at the business layer and can be very custom.

 ii.On before save:  We set the properties that the user set to the validation objects.  Which is a pain, but a necessary piece obviously.  

 iii.On before save:  We loop through and validate each field.  This can add violations to the business scope.

 iv.On Before save:  If there are violations the save aborts.  There is a collection of the reasons why that the presentation layer can see.

Also, supposedly you are suppose to be able to do some simple validation through the gui but I can seem to find that as well. Feeling kind of dumd.

Anyway, sorry for the long post, but I am trying to fit this code into this system and cannot at this time. I was hoping I could do it with partial classes and making my own code generation section, but I cannot get this to work. Any help would be appreciated.

Bryan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Jul-2006 21:01:31   

BringerOD wrote:

I am new to this software and am very excited about using it.

I have read most of the documentation and experimented with the generation of the some code, but am having some problems still. I was hoping some of the local experts could assist me further.

1) No matter what I do I cannot get the software to generated partial classes. I am using the VB.NET generation if that matters. I see no where in the options that sets this. I know you can do it, because the demo example generated code has it in there, but for some reason I cannot find how to turn this feature on. Maybe it does not work in the demo.

In VB.NET, the keyword 'Partial' isn't mandatory. So the classes generated aren't marked as Partial as that's not required: you can just add another file with the same class definition and in there mention 'Partial' in the class definition, and it should work.

2)Validation, currently I code my business layer by hand, which is very time consuming, but allows a lot of control obviously. Here is what we do:

a.We have made a series of classes that handle all sorts of types of data.

  i.EmailFieldValidator:  This validates if it’s a good email,  it can check the domain and ping it, etc.

  ii.LongValidator:  Has settings to check if required,  if you have a minimum number value or maximum etc.

  iii.I can go on but we have class for every type of field in our system.

b.Then what we do is each business object maintains a collection of violations. These violations can be updated from the validator’s or in a custom manner. Anywhere in our code we can add a validation error to the business objects collection, and if the person using this object tries to save, the action will not be performed and the validation information is shown to the user. This makes it easy to right the presentation layers in a consistent manner. Also this information is localized. Here is the process.

  i.On creation of an object:  We initialize the validation objects and set the properties we want for each.  i.e.  Is this required,  is there a minimum value, should we check and ping the domain, etc.  For each business object.  Its like setting database constraints but at the business layer and can be very custom.

 ii.On before save:  We set the properties that the user set to the validation objects.  Which is a pain, but a necessary piece obviously.  

 iii.On before save:  We loop through and validate each field.  This can add violations to the business scope.

 iv.On Before save:  If there are violations the save aborts.  There is a collection of the reasons why that the presentation layer can see.

This is possible through the validation framework. You can implement your validation logic in validator classes which are derived from ValidatorBase (see manual). you can set rule lists etc. which are violated in the entity from the validator object as it gets the entity it works on passed in.

Also, supposedly you are suppose to be able to do some simple validation through the gui but I can seem to find that as well. Feeling kind of dumd.

No, the designer doesn't offer validation rule definitions. It turned out that to define the rules there was more time consuming than just typing them in in code, so we left that out of the designer.

Anyway, sorry for the long post, but I am trying to fit this code into this system and cannot at this time. I was hoping I could do it with partial classes and making my own code generation section, but I cannot get this to work. Any help would be appreciated. Bryan

Please let me know if you still can't add a partial class to an entity class in vb.net, as you should simply be able to do: Public Partial Class CustomerEntity ' your code here End Class

and place that in the generated code vs.net project. Be sure the namespaces defined in your partial class of course match the one of the class you're extending. Are you using adapter or selfservicing?

Frans Bouma | Lead developer LLBLGen Pro
BringerOD
User
Posts: 70
Joined: 15-Jul-2006
# Posted on: 15-Jul-2006 23:04:12   

I use enumerations for a lot of my tables.

I store an integer field in the database of the enumeration.

I want to expose the enumeration to app layer.

How do I remove the datafield from view and replace it with an enumeration? Also, when I databind this to a grid or page, I usually pull the data from the enumeration and display it in a dropdown.

I have this working in my current app, but I am having trouble figuring out how I am going to do it here.

BringerOD
User
Posts: 70
Joined: 15-Jul-2006
# Posted on: 15-Jul-2006 23:04:53   

Thanks for the help here.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Jul-2006 00:04:41   

BringerOD wrote:

I use enumerations for a lot of my tables.

I store an integer field in the database of the enumeration.

I want to expose the enumeration to app layer.

How do I remove the datafield from view and replace it with an enumeration? Also, when I databind this to a grid or page, I usually pull the data from the enumeration and display it in a dropdown.

See our complex databinding example which illustrates this.

Frans Bouma | Lead developer LLBLGen Pro