FieldCompareValuePredicate

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 31-Mar-2011 12:49:26   

LLBLGEN 3.1 Rel Date 16/03/2011 .NET frame work 2.0 Windows Application DB: Oracle 9i / 10g MSORACLE

In the following FieldCompareValuePredicate, generalmeetdate I am passing null depending on the business logic. Now when it is null it throws exception. Is there a way to check this ?

var filterdescription = new FieldCompareValuePredicate(GeneralmeetFields.Description, null, ComparisonOperator.Equal, description); var Generalmeetdate = new FieldCompareValuePredicate(GeneralmeetFields.Generalmeetdate, null, ComparisonOperator.Equal, date);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 31-Mar-2011 14:38:17   

IPredicate Generalmeetdate = date==null ? new FieldCompareNullPredicate(GeneralmeetFields.Generalmeetdate, null) : new FieldCompareValuePredicate(GeneralmeetFields.Generalmeetdate, null, ComparisonOperator.Equal, date);

better is to do: IPredicate Generalmeetdate = GeneralmeetFields.Generalmeetdate==(date ?? DBNull.Value);

this will auto-select the predicate to use based on the date value.

Frans Bouma | Lead developer LLBLGen Pro
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 31-Mar-2011 15:41:27   

Otis wrote:

IPredicate Generalmeetdate = GeneralmeetFields.Generalmeetdate==(date ?? DBNull.Value);

Operator ?? cannot be applied to operands of type 'string' and 'system.DBnull'

I am passing date as string

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 31-Mar-2011 16:52:51   

shekar wrote:

Otis wrote:

IPredicate Generalmeetdate = GeneralmeetFields.Generalmeetdate==(date ?? DBNull.Value);

Operator ?? cannot be applied to operands of type 'string' and 'system.DBnull'

I am passing date as string

Well, you do know a little bit about C# or not? simple_smile object toCompareWith = date; if(toCompareWith == null) { toCompareWith = DBNull.Value; } IPredicate Generalmeetdate = GeneralmeetFields.Generalmeetdate==toCompareWith;

Frans Bouma | Lead developer LLBLGen Pro