Dynamic Linq Datetime where

c# dynamic-linq linq

Question

I'm trying to write a query using dynamic linq, but I'm having trouble using DateTime

  • a list of results from a previous query may be found in queryResults.

  • The DateTime argument is sr.FromDate.

I'm attempting to get all results that are larger than or equal to the sr.FromDate parameter.

var z = queryResults
            .Where("Min(Datetime) >= @0", sr.FromDate)
            .ToDictionary(g => g.FirstOrDefault().ServiceInstanceId, g => g.ToList());

exeption:

ParseError  ,    '.' or '(' expected

EDIT:

Just to be clear, I'm using a dynamic Linq object called Zzz-43-Zzz, which has text, int, and date arguments. If any of those values aren't null, I'm constructing a query.

EDIT 2

I was able to solve my privus issue, but now I'm having trouble building the query because of this.

  private static string GetQueryTemplet(string criteria)
    {

        switch (criteria)
        {

            case "FromDate":
                return " Min(Track.Datetime) >= {0} ";
            case "ToDate":
                return " Max(Track.Datetime) <=  {0} ";

             default:
                return "";
        }

then I transmit the information to

 var z = queryResolts
             .Where(query)
            .ToDictionary(g => g.Key, g => g.Select(h => h.Track));

I'm seeing this exception for some reason.

Operator '>=' incompatible with operand types 'DateTime' and 'Int32'

I tried several different approaches to parse it, but nothing worked.

Regards, Miki

1
0
10/25/2012 2:20:01 PM

Accepted Answer

assuming you have a DateTime Column in your results

var z = queryResults
            .Where(result => result.DateTime >= sr.FromDate)
            .ToDictionary(g => g.FirstOrDefault().ServiceInstanceId, g => g.ToList());
1
10/24/2012 9:29:52 AM


Related Questions





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