TestCurrentFieldValueForNull -- "Generic" way to test an Entity's Fields

Posts   
 
    
caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 13-Dec-2006 22:02:06   

Hello --

I'm using C#, .Net 1.1, LLBLGen 1.0.2005.1 (June 19th, 2006), Self Servicing (2 classes)

I'm trying to find a way to have a common base class or routine test non-nullable fields to see if their current value is null, before attempting to save the entity to the database.

I was thinking that it would be fairly easy using TestCurrentFieldValueForNull, but that method only seems to be in the generated code and not in an interface or entity base class.

Is there a base class or interface that allows me to test if the current field value is null? I saw that TestCurrentFieldValueForNull calls base.CheckIfCurrentFieldValueIsNull(int x), but that method is protected.

(I know I'm using an older version and release of LLBLGen, but it doesn't look like TestCurrentFieldValueForNull has changed in 2.0.x.)

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Dec-2006 07:12:17   

I don't know how generic do you want it to be? You can have a method in the BusinessLayer does the check.

You may also generate your method into the generated code, by modifying the templates.

I saw that TestCurrentFieldValueForNull calls base.CheckIfCurrentFieldValueIsNull(int x), but that method is protected.

You can modify the templates and set it to public if you want.

caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 14-Dec-2006 16:03:25   

Walaa wrote:

I don't know how generic do you want it to be? You can have a method in the BusinessLayer does the check.

Basically, I was hoping my base biz class could run a routine like "CheckRequiredFieldsForNull" or something like that. The child class would create array of structs that contains the field or fieldIndex to test and an error message. When Save() is called on the biz class, the validation routine would run.

Something like:


            foreach (RequiredField r in this.RequiredFields)
            {
                if (this.entity.TestCurrentFieldValueForNull(r.Index, r.ErrorMessage))
                    this.Messages.Add(r.Message);
            }

I don't know if that makes sense or not.

I'll take a look at either modifying the templates and/or adding an Interface which has TestCurrentFieldValueForNull to the Entity classes.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 15-Dec-2006 11:10:37   

caseyry wrote:

Walaa wrote:

I don't know how generic do you want it to be? You can have a method in the BusinessLayer does the check.

Basically, I was hoping my base biz class could run a routine like "CheckRequiredFieldsForNull" or something like that. The child class would create array of structs that contains the field or fieldIndex to test and an error message. When Save() is called on the biz class, the validation routine would run.

Something like:


            foreach (RequiredField r in this.RequiredFields)
            {
                if (this.entity.TestCurrentFieldValueForNull(r.Index, r.ErrorMessage))
                    this.Messages.Add(r.Message);
            }

I don't know if that makes sense or not.

I'll take a look at either modifying the templates and/or adding an Interface which has TestCurrentFieldValueForNull to the Entity classes.

Thanks.

You can always decide to use a validator class on the entity of course which does field validation on before save. Please check the manual (using the generated code -> Validation per field or per entity) for further ideas on validation and how to get started.

Frans Bouma | Lead developer LLBLGen Pro