0

I'm very new to lambda expressions and want to know how to get all the dates which are between x date and y date. So far I have written it to get all of the data based on the id of an object but now I need to write code to get the data based on id, start date and end date.

Here is what I have so far:

data = ClientsRepo.GetAllClients().DistinctBy(x => x.ClientID);

my start date and end date is in my razor page which is defined here:

@code{
DateTime? startDateInit;
DateTime? endDateInit;

protected override async Task OnInitializedAsync()
{
    startDateInit = DateTime.Now;
    endDateInit = DateTime.Now.AddDays(10);
}


}

Steve Greene
  • 12,029
  • 1
  • 33
  • 54
jacky
  • 65
  • 1
  • 8
  • 1
    Who closed this? That thread is NOT a duplicate of this question. "Getting dates between" and "Searching dates between" are not the same thing at all. – Bennyboy1973 Oct 26 '21 at 15:26
  • 1
    @Bennyboy1973 ugh, you're right. I edited it earlier today to what you saw because I am apparently bad at reading. I've changed it back. Thanks for the catch. – Kirk Woll Oct 26 '21 at 19:28
  • What does each record in `ClientsRepo` - `Client` I'm assuming - look like, specifically the date field you want to filter on? – MrC aka Shaun Curtis Oct 26 '21 at 19:42
  • 1
    `DistinctBy` is not really a search function. Making some assumptions that you want all records within the dates that match an id: `data = ClientsRepo.GetAllClients().Where(x => x.ClientID == myClientID && x.ClientDate >= startDateInit && x.ClientDate <= endDateInit).ToList();` – Steve Greene Oct 26 '21 at 22:28
  • @SteveGreene Hi, steve, thank you for that lambda exp. It was all I needed! – jacky Oct 27 '21 at 10:32

0 Answers0