Using Dynamic Linq to Filter entity by datetimeoffset columns

c# dynamic-linq entity-framework-6 linq

Question

Using the DynamicLinq dll, I'm doing a dynamic linq and submitting a dynamic filter that looks like the one below.

"CreatedDate=System.DateTimeOffset.Parse(\"2017-11-17 22:07:04.9192538 +00:00\")",

But I keep receiving the message "System does not exist." But I also tried the following, with no success.

"CreatedDate=(\"2017-11-17 22:07:04.9192538 +00:00\")",

yet receiving the following message

Operator '=' incompatible with operand types 'DateTimeOffset' and 'String' (at index 11)

How should I use dynamic linq and EF to filter the date time offset columns?

Code

IQueryable<T> query = Set<T>();

if (!string.IsNullOrEmpty(filter))
    query = Dynamic.DynamicQueryable.Where(query, filter);
1
0
4/30/2018 8:08:46 PM

Popular Answer

If the string is converted into a DateTimeOffset object like follows:

var dateTime = DateTimeOffset.Parse("2017-11-17 22:07:04.9192538 +00:00")

then use this:

query.Where("CreatedDate==DateTimeOffset(@0)", dateTime)
0
5/1/2018 6:41:52 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow