Checking for null values

Posts   
 
    
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 06-Sep-2005 16:02:20   

Hi

After fetching an entity, I want to check whether one of my fields (a Int32 field) is null or not.

I found that I can do that by getting my field through the Fields array and checking the IsNull property, but it means that the strong-typed property representing my field remains useless.

I consider the IsNull attribute as part of the data retrieved (since ValueTypes, like Int32, cannot be assigned to null), so I wonder why not having the IsNull property in the Entity level, for each ValueType?

PersonEntity.Age PersonEntity.AgeIsNull PersonEntity.HasChildren PersonEntity.HasChildrenIsNull . . .

or am I missing something here?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Sep-2005 16:39:38   

orenpeled wrote:

Hi

After fetching an entity, I want to check whether one of my fields (a Int32 field) is null or not.

I found that I can do that by getting my field through the Fields array and checking the IsNull property, but it means that the strong-typed property representing my field remains useless.

No, you can use: personEntity.TestOriginalFieldValueForNull(PersonFieldIndex.Fieldname); This is strongly typed.

I consider the IsNull attribute as part of the data retrieved (since ValueTypes, like Int32, cannot be assigned to null), so I wonder why not having the IsNull property in the Entity level, for each ValueType?

PersonEntity.Age PersonEntity.AgeIsNull PersonEntity.HasChildren PersonEntity.HasChildrenIsNull . . .

or am I missing something here?

Because it would create a lot of properties which aren't really necessary, as there is already a single method which takes care of that simple_smile

Frans Bouma | Lead developer LLBLGen Pro
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 06-Sep-2005 22:56:17   

OK, so what actually happens in the TestOriginalFieldValueForNull method?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Sep-2005 10:20:03   

orenpeled wrote:

OK, so what actually happens in the TestOriginalFieldValueForNull method?

You could have found that out yourself as it's in the generated code wink

return base.Fields[(int)fieldIndex].IsNull;

Frans Bouma | Lead developer LLBLGen Pro
orenpeled
User
Posts: 53
Joined: 25-Jul-2005
# Posted on: 07-Sep-2005 18:14:47   

Well, this is what I intended to do at first, but I wanted to avoid referencing the Fields array I guess I have no choice though

Thank you very much for answering and for being kind despite my unnecessary question smile