MIkCode
MIkCode

Reputation: 2845

Dynamic Linq Datetime where

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

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

Upvotes: 0

Views: 1216

Answers (1)

awright18
awright18

Reputation: 2333

Assuming your results have a DateTime Column

var z = queryResults
            .Where(result => result.DateTime >= sr.FromDate)
            .ToDictionary(g => g.FirstOrDefault().ServiceInstanceId, g => g.ToList());

Upvotes: 1

Related Questions