I have a MS SQL server with table who is linked on itself
| Id| PreviousId| Decription |
|---|:---------:|------------:|
| 1 | null | Blah |
| 2 | 1 | Blah |
| 3 | 2 | Blah |
And I need to get list of all records starting from Id=3
.
My list should look like:
public class Record{
public int Id {get;set;}
public int? PrevId {get;set;}
public string Desc {get;set;}
}
List<Record> records= new List<Record>();
/*Code to get all records*/
//Result
record[0] = Record(){Id=3,PrevId=2,Descr="Blah"}
record[1] = Record(){Id=2,PrevId=1,Descr="Blah"}
record[2] = Record(){Id=1,PrevId=null,Descr="Blah"}
Thank you!
EDIT1: Sorry guys, but i didn't mentioned that ID are not in order. And there can be situation when, for example, record with ID=17 link to previous record with id =12