Null Values in Bound control

Posts   
 
    
craigmain
User
Posts: 22
Joined: 17-Apr-2005
# Posted on: 23-Apr-2005 20:16:12   

Hi,

I did a search on the forum before asking this silly question. Where and how should I check for null or empty values when using a data bound list.

At the moment I can add as many entries as I like even though some fields should not be able to be null (or empty). I am using the dev express grid, although this should apply to any data bound grid control.

Regards Craig.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Apr-2005 10:22:30   

Not nullable fields can't be set to null in 1.0.2004.2, this is build in.

In a grid, it's hard to set a field to null, as you can't specify such a value. What's therefore the situation you're referring to? A user which deletes the cell's contents by selecting it, and pressing DEL ?

Frans Bouma | Lead developer LLBLGen Pro
craigmain
User
Posts: 22
Joined: 17-Apr-2005
# Posted on: 25-Apr-2005 10:56:00   

Hi Otis,

Your code interprets null values to a particlar null representation, for example A null gui is System.Guid.Empty. My database field does not allow null values (the entity should not be able to commit to the database with empty values)

When I add new entities to the collection it does not enforce the not null values at any point until the entity collection is submitted for update.

I need to know how to ascertain whether an entity field is allowed to be null (on the client side) (System.Guid.Empty / string.Empty etc), and where I can enforce this in the entity collection. Perhaps in the validator?

I do not want the add to commit without the required fields entered.

Regards Craig

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Apr-2005 11:20:42   

craigmain wrote:

Hi Otis,

Your code interprets null values to a particlar null representation, for example A null gui is System.Guid.Empty. My database field does not allow null values (the entity should not be able to commit to the database with empty values)

When I add new entities to the collection it does not enforce the not null values at any point until the entity collection is submitted for update.

I need to know how to ascertain whether an entity field is allowed to be null (on the client side) (System.Guid.Empty / string.Empty etc), and where I can enforce this in the entity collection. Perhaps in the validator?

In 1.0.2004.2 I've added this to adapter and selfservicing (in previous versions, it was only available in selfservicing): entity.Fields[index].IsNullable

Then, in an IEntityValidator implementation you check whether entity.Fields[index].IsNullable is false AND entity.Fields[index].IsChanged is true. If not, a not-nullable field hasn't received a value and you should throw an ORMEntityValidationException, which will terminate a transaction in progress.

This is enforced on save. I think that's the right place to do so, otherwise the user hasn't had time to add values wink

Set the IEntityValidator implementation in an entity initialisation include template or in a user code region. See the documentation for tips how to do that (1.0.2004.2) -> Using the generated code - Adding your own code to the generated classes

Frans Bouma | Lead developer LLBLGen Pro