Using Dynamic Linq to Filter entity by datetimeoffset columns

c# dynamic-linq entity-framework-6 linq

Question

I am doing a dynamic linq using the DynamicLinq dll where-in I am sending the dynamic filter constructed like the one below

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

However, i am getting an error that System does not exist. However, I also tried the following but no luck.

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

But getting the below message

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

What is the right approach to filter the date time offset columns using dynamic linq and EF?

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 you parse the string into a DateTimeOffset object like:

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

Then you can 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