0

I'm using dynamic linq to build a query in runtime. I'm preparing the following command

var temp = list
    .AsQueryable()
    .Where("Date<DateTime(2014,10,22,21,05,56)")
    .Select("it");
return temp.Cast<T>().ToList();

The condition is not executing properly and i'm getting a wrong set of results. My filter condition is dynamic and i'll generate it only in run time. Can you help me in resolving this issue. Is there a Hour minute second comparison possible in dynamic linq?

ToYonos
  • 16,469
  • 2
  • 54
  • 70
arun thatham
  • 500
  • 1
  • 4
  • 13

2 Answers2

2

Please refer this link

As per the information from that link

Note that constructor invocations are not prefixed by new. The following example creates a DateTime instance for a specfic year, month, and day using a constructor invocation:

orders.Where("OrderDate >= DateTime(2007, 1, 1)");

Only difference I can see there is it is taking only 3 arguments. The author may not have implemented the overloaded version. Try with three parameters, instead.

Credits

Community
  • 1
  • 1
Rama Kathare
  • 920
  • 9
  • 29
  • My question is I cannot pass a parameter. I need to construct the datetime on my own. When downloaded the source I can't find their method which takes 3 parameters – arun thatham Nov 21 '14 at 19:35
1

When I use the NuGet package I can execute your predicate alright. But I would use a parameter anyway:

var temp = list
    .AsQueryable()
    .Where("Date < @0", new DateTime(2014,10,22,21,05,56))
    .Select("it");
return temp.Cast<T>().ToList();
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291