DbFunctionCall in Predicate

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 02-Nov-2010 21:40:36   

I am having a hard time trying to figure out how to write this query. Can anyone help?

I'm trying to convert the following SQL into a predicate.

/* Display 14 days after activated date. 10/14 + 14 = 28 - Show on the 28th. Remove from display 28 days after activated date. */ WHERE (GETDATE() >= DATEADD(DAY, 14, [ActivatedDate]) AND GETDATE() <= DATEADD(DAY, 28, [ActivatedDate]))

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 02-Nov-2010 22:28:26   

Hi

Can you show us what you have got so far, and explain why it is not working...?

Matt

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 03-Nov-2010 20:01:44   

OK, I finally figured this out. Here is what I did.


DbFunctionCall getDate = new DbFunctionCall("GETDATE", new object[] { });
DbFunctionCall dateAddStart = new DbFunctionCall("DATEADD(DAY, 14, {0})", new object[] { NominationFields.ActivatedDate });
DbFunctionCall dateAddEnd = new DbFunctionCall("DATEADD(DAY, 28, {0})", new object[] { NominationFields.ActivatedDate });
IPredicate startDayFilter = (NominationFields.ActivatedDate.SetExpression(getDate) >= dateAddStart);
IPredicate endDayFilter = (NominationFields.ActivatedDate.SetExpression(getDate) <= dateAddEnd);
PredicateExpression dayFilter = new PredicateExpression();
dayFilter.AddWithAnd(startDayFilter);
dayFilter.AddWithAnd(endDayFilter);
filter.PredicateExpression.AddWithAnd(dayFilter);

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2010 06:04:57   

Congrats simple_smile

David Elizondo | LLBLGen Support Team