complex IPredicateExpression

Posts   
 
    
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 20-Apr-2010 13:36:42   

I can't get an IPredicateExpression that is identical to the following sql where clause right.

Does anyone have an example of similar code I can study?

    (fieldA = 10) 

AND ( (getdate() BETWEEN FieldBegin AND FieldEnd) OR (FieldBegin >= getdate()) ) AND (FieldB = 55) AND (FieldC = 34)

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 20-Apr-2010 14:15:14   

I guess you need to use a DbFunctionCall for the GetDate variable in combination with a FieldCompareExpressionPredicate.

Regards, Danny

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 20-Apr-2010 21:09:30   

Can you post what you have got so far, and the SQL it generated...?

Matt

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 20-Apr-2010 22:23:59   

Something like this (in VB.NET) :

        Dim filter As New PredicateExpression
        Dim fld As New EntityField2("currDate", New DbFunctionCall("getdate()", Nothing))

        filter.Add(New FieldCompareExpressionPredicate(AccountFields.CreatedOn, Nothing, ComparisonOperator.GreaterThan, New DbFunctionCall("getdate()", Nothing)))
        filter.AddWithOr(New FieldBetweenPredicate(fld, Nothing, AccountFields.CreatedOn, AccountFields.ModifiedOn))

Regards, Danny