Pregunta

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...

¿Fue útil?

Solución

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'"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top