-8

Please check my code. I want to filter the list by date, but this code doesn't working.

List<QueryRow> queryResult = App.StorageRepository.Query("appointments_appointment");
queryResult.Where(item => 
    {
        var startDate = Convert.ToDateTime(item.Document.GetProperty("startDate"));
        if (startDate == date)
            return true;
        else
            return false;
    });
maccettura
  • 10,514
  • 3
  • 28
  • 35
Meteoric
  • 136
  • 11

1 Answers1

0

I don't now exactly what your code does but I suggest you try to see if there are any dates in a collection that match with a given date (see example 2).

Or if you are trying to get the elements that match a given date use example 1

      // example date
       DateTime date = new DateTime(2005,4,10);
      // data collection
      List<QueryRow> queryResult = App.StorageRepository.Query("appointments_appointment");

(Example 1 Where())

Use where to check where the date of QueryRow is equal to the given date. If it does return that QueryRow.

       IEnumerable<QueryRow> results = queryResult.Where(item => Convert.ToDateTime(item.Document.GetProperty("startDate")) == date)

       // loop the result items that matched the search result
       foreach (QueryRow result in results)
       {
           // do something with the row
       }

(Example 2 Any())

Check if the given date exists in collection. By using any it will check if there are any matching items with the date that is equal to the given date. If thre is on it will return true else false.

  bool dateExists = queryResult.Any(item => Convert.ToDateTime(item.Document.GetProperty("startDate")) == date);
Timon Post
  • 2,779
  • 1
  • 17
  • 32
  • Hi Thanks for your answer. can I debug the were method? – Meteoric May 10 '17 at 19:01
  • No you can't debug lamda expressions inside Linq method. But you can check the result what it is giving back. And if you are not sure if the DateTime is the same witch you are trying to compare, than look at the input and see how that is formatted and check what formatted date `Document.GetProperty("startDate")` returns. – Timon Post May 10 '17 at 19:04
  • @TimonPost *"No you can't debug lamda expressions inside Linq method"* -- i may be misunderstanding you, but I put breakpoints in lambdas all the time. – 15ee8f99-57ff-4f92-890c-b56153 May 10 '17 at 19:55