0

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

MIkCode
  • 2,655
  • 5
  • 28
  • 46

1 Answers1

1

Assuming your results have a DateTime Column

var z = queryResults
            .Where(result => result.DateTime >= sr.FromDate)
            .ToDictionary(g => g.FirstOrDefault().ServiceInstanceId, g => g.ToList());
Andrei
  • 55,890
  • 9
  • 87
  • 108
awright18
  • 2,255
  • 2
  • 23
  • 22
  • i have to use dynamic linq http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx – MIkCode Oct 24 '12 at 09:40
  • @MIkCode why? You're not gaining any benefit from it in this exact scenario. Do you need to dynamically change the column name or something? If not; don't use it because you don't need it. – Doctor Jones Oct 24 '12 at 10:45