How to create filter: DateAdd with column argument

Posts   
 
    
veljkoz
User
Posts: 25
Joined: 31-Mar-2010
# Posted on: 02-Jul-2017 15:10:40   

Hi,

I have a table like (other properties removed for brevity):

Updates ( LastUpdated DateTime, UpdateEveryXMinutes int)

I'd like to get all rows that are ready for update, i.e.:

WHERE LastUpdated < DateTime.Now - UpdateEveryXMinutes

Currently, what I do is:

var dbDateAdd = new DbFunctionCall("DATEADD(minute, -UpdateEveryXMinutes, GETDATE())", new object[] { });
filter.PredicateExpression.AddWithAnd(UpdatesFields.LastUpdated < dbDateAdd);

What I would like to know is of a way to pass the column name as argument to the dateAdd, to avoid issues in using coplex query which includes column with the same name on another table.

Or, if you can suggest a different approach that would be fine as well. (btw, I don't care if DateTime.Now is taken on app server or db server).

Using Sql Server 2016, LLBLGen 5.2, adapter.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Jul-2017 08:35:50   

Hi veljkoz. Just pass the field object as argument:

var dbDateAdd = new DbFunctionCall("DATEADD(minute, -{0}, GETDATE())", new object[] { UpdatesFields.UpdateEveryXMinutes });
David Elizondo | LLBLGen Support Team
veljkoz
User
Posts: 25
Joined: 31-Mar-2010
# Posted on: 03-Jul-2017 10:04:36   

That easy, huh? simple_smile

Thanks