FetchScalar returning null after

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 17-Jul-2017 12:26:23   

Hello,

I have encoutered a problem with the FetchScalar<T> method after overriding the FetchProjection method.

FetchScalar<int> started to returning a null value whenever the query returned 0.

When I remove the the line of code where I'm adding the predicate expression (parameters.FilterToUseAsPredicateExpression.Add(field.Equal(1)); ) it works again as it should. The return value is 0.


public override void FetchProjection(List<IDataValueProjector> valueProjectors, IGeneralDataProjector projector, QueryParameters parameters)
{
       var field = .....

       parameters.FilterToUseAsPredicateExpression.Add(field.Equal(1));
    
       base.FetchProjection(valueProjectors, projector, parameters);        
}

And this is how I call the code


int count = _adapter.FetchScalar<int>(query);

Is there something wrong with my code ?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 17-Jul-2017 21:23:14   

What's the LLBLGen RTL version?

Does it return the corrct rows when the filter allow for it?

Please check the produced SQL, post it here, please. Make sure there is no exception produced that got swallowed somewhere.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 18-Jul-2017 10:21:55   

Also, if a scalar value in the DB doesn't result into a value, a NULL is returned, which results in a null value. So for scalar fetches which can result in 0 rows (and thus no value!) should be used with a nullable type, e.g. int?, not int.

Frans Bouma | Lead developer LLBLGen Pro
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 25-Jul-2017 13:31:51   

Yes, the query was returning a null value. You can close the thread.