-1

I have table in SQL

id   datetime     
---|------------|
1  | January    |
2  | February   | 
3  | March      | 
4  | April      |
5  | May        |  
6  | June       | 
7  | July       | 
8  | August     | 
9  | September  | 
10 | October    | 
11 | November   | 
12 | December   | 

When select record result start from january but I want to get complete record but start from july...

Fahmi
  • 37,315
  • 5
  • 22
  • 31
  • could you please provide your expected output in table format? – Fahmi Dec 27 '18 at 06:49
  • 1
    [Queryable.Skip(IQueryable, Int32) Method](https://learn.microsoft.com/en-us/dotnet/api/system.linq.queryable.skip?view=netframework-4.7.2) and [Queryable.OrderBy Method](https://learn.microsoft.com/en-us/dotnet/api/system.linq.queryable.orderby?view=netframework-4.7.2) – TheGeneral Dec 27 '18 at 06:49
  • id datetime ---|------------| 7 | July| 8 | August | 9 | September | 10 | October | 11 | November | 12 | December | 1 | January | 2 | Feb | 3 | March | 4 | April | 5 | May | 6 | June | – Naveed Ahmad Dec 27 '18 at 06:51
  • 1
    You need something like `Union` or `Concat` I think the accepted answer here is what you are looking for : https://stackoverflow.com/questions/11426615/linq-union-usage However, if the set of records is small, I would take the whole set and rearrange it on the application server. – Leron Dec 27 '18 at 06:56
  • @NaveedAhmad, please show some code that you did. – er-sho Dec 27 '18 at 06:56
  • am just getting list of record.. Like that.. var Monthslist = Model.Select(d => d.MonthId).Distinct().ToList(); – Naveed Ahmad Dec 27 '18 at 07:10
  • @NaveedAhmad, try this => `var Monthslist = Model.Where(d => d.MonthId > 6).Select(d => d.MonthId).Distinct().ToList();` and let me know – er-sho Dec 27 '18 at 07:36
  • @er-shoaib I have try this but getting same record.. – Naveed Ahmad Dec 27 '18 at 07:57
  • @NaveedAhmad, please show your code that show how you'd implement above code? – er-sho Dec 27 '18 at 07:58
  • var Monthslist = Model.Where(d => d.MonthId > 6).Select(d => d.MonthId).Distinct().ToList(); foreach (var item in Monthslist) { var months = Model.Where(d => d.MonthId == item).FirstOrDefault(); – Naveed Ahmad Dec 27 '18 at 08:00
  • Please EDIT YOUR QUESTION with what you have tried, don't post it in the comments. – Ian Kemp Dec 27 '18 at 09:58
  • @NaveedAhmad, what you try to do in `foreach` ? bcoz you already have `item` with `MonthId` you do not need to do so... – er-sho Dec 27 '18 at 10:40

1 Answers1

0

You want to start from July so first make list which start from july. And then union it with rest of items.

Try with this

var result = modelList.Where(x => x.id > 6).ToList().
                Union(modelList.Where(y => y.id < 7).Distinct().ToList()).ToList();
Md. Zakir Hossain
  • 1,082
  • 11
  • 24