Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing DateTime values in EntitySQL when starting with a querystring

I am using the QueryBuilder as following:

var queryString = String.Format(
    "SELECT VALUE e FROM Entity AS e WHERE e.EndDate {0} {1} ",
    operator,
    DateTime.Today.AddYears(1).ToString("d", DateTimeFormatInfo.InvariantInfo)
);
ObjectQuery<Entity> query = new ObjectQuery<Entity>(queryString, Context);

Please note that I extremely simplified this example and that my goal is to build the query as string before creating a QueryBuilder instance. (As long as this is possible)

I already tried the following

...DateTime.Today.AddYears(1)...
...DateTime.Today.AddYears(1).ToString()...
...DateTime.Today.AddYears(1).ToString("yyy\MM\dd")...

which all result in a exception which says that I either cannot compare DateTime with a String or with a Int32.

I'm beginning to asking me if this is possible at all with this approach...

like image 673
sra Avatar asked Dec 17 '25 15:12

sra


1 Answers

In Entity SQL DateTime literals must be expressed in the following format:

DATETIME'2012-02-02 16:26'

where both the date and time parts are mandatory. For example:

"SELECT VALUE e FROM Entity AS e WHERE e.EndDate > DATETIME'2012-02-02 16:26'"
like image 68
Enrico Campidoglio Avatar answered Dec 19 '25 04:12

Enrico Campidoglio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!