Dynamic Linq Datetime where

c# dynamic-linq linq

Question

im using dynamic linq in order to build a query and im having an issue with DateTime

  • queryResults- contain a list of result from a previous query .

  • sr.FromDate- a DateTime parameter

what im trying to do is to get the all the result that greater and 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 Clarify we im using dynamic linq SR object contains string int and date parameters if the values of the parameters isnt null im building a query

EDIT 2

i figure out my privus problem but now i have another problem , im using this in order to build the query

  private static string GetQueryTemplet(string criteria)
    {

        switch (criteria)
        {

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

             default:
                return "";
        }

than im passing the data to

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

for some reason im getting this exception

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

i tried to parse it in many ways but nothing work ...

thanks miki

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

Accepted Answer

Assuming your results have a DateTime Column

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