I am using EF core 6, I need to get the records for previous month & next month using LINQ . There is a dropdown list with months name , I will be sending month number of the selected month to the LINQ condition
If I select January ,it should get results of December full month records from previous year & current year February whole month records.
When i use the below predicate, It doesn't provide proper results
Func<Products, bool>? predicate = i => i.CreatedDate.Month > month + 1 && i.CreatedDate.Month < month - 1;
Product
ID Name CreatedDate Amount
1 John 21/12/2021 1000
2 Mark 10/12/2021 2000
3 Steve 02/01/2022 3000
4 Arun 21/01/2022 4000
5 Adi 10/02/2022 5000
6 Sanjay 11/02/2022 6000
7 Sanjay 14/02/2022 7000
I also need to get the total amount of each month based on the month selected
If I select January month the result should be
Month Value Quantity
December 3000 2
January 7000 2
February 18000 3
I am new to LINQ, please provide suggestions
Model -- Product
public int Id { get; set; }
public string? Name { get; set; }
public int? Amount{ get; set; }
public DateTime CreatedDate { get; set; }