Date Math

Posts   
 
    
jg
User
Posts: 25
Joined: 29-Dec-2011
# Posted on: 09-Feb-2012 23:14:58   

Version Info: 3.1 Final Adapter .Net 4.0 C# SQL Server 2008

I am having trouble figuring out how to do Date Math in LLBLGen.

Here is the SQL query that I am trying to achieve:

SELECT DISTINCT w.WaiverID FROM Waiver w JOIN WaiverWorkflowLog wwl ON w.WaiverID = wwl.WaiverID JOIN WaiverWorkflowQueue wwq ON wwl.QueueID = wwq.QueueID WHERE DATEADD(hh, wwq.WarningThreshold, wwl.AssignedDate) >= CURRENT_TIMESTAMP)

It is a simple enough query, but I am struggling with the LLBLGen syntax. The part I can't figure out is the DateAdd in the Where clause. Warning Threshold is the number of hours after a task is assigned that a warning email should be sent out. So I need to add the warning threshold to the assigned date and see if we need to send out the email.

Here is the C# code that I want (but this won't compile):

bucket.PredicateExpression.Add( WaiverWorkflowLogFields.AssignedDate.AddHours(WaiverWorkflowQueueFields.EscalationThreshold) >= executionTime);

How should I go about doing this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
jg
User
Posts: 25
Joined: 29-Dec-2011
# Posted on: 10-Feb-2012 17:41:39   

Thanks!

This is what I came up with and it works:

DbFunctionCall warningDate = new DbFunctionCall("DATEADD(hh, {0}, {1})", 
     new object[] { WaiverWorkflowQueueFields.WarningThreshold,
     WaiverWorkflowLogFields.AssignedDate });
IPredicate warningFilter = new EntityField2("WarningDate", warningDate) <= 
     executionTime;
bucket.PredicateExpression.Add(warningFilter);