I have the following class that is used to hold data for reporting only.
public class AdminDetail
{
public int Row { get; set; } // This row needs a unique number
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Title { get; set; }
public string Status { get; set; }
public string Type { get; set; }
public string Level { get; set; }
public string Order { get; set; }
}
Populated with the following select on the _table collection.
details = from t in _table
select new AdminDetail
{
PartitionKey = t.PartitionKey,
RowKey = t.RowKey,
Title = t.Title,
Status = t.Status,
Type = t.Type,
Level = t.Level,
Order = t.Order
};
detailsList = details.OrderBy(item => item.Order).ThenBy(item => item.Title).ToList();
After the rows are sorted with the last statement I would like to give to put a value into the RowID
that corresponds to the row. So if I had three instances returned I would like them to have the RowID
1,2 and 3.
Is there a way that I can do this with LINQ?
You could do it using the
Selectoverload which provides an index, but you’d probably want to do the projection toAdminDetailafter the ordering:Aside from anything else, this way if
_tableis a LINQ to SQL table (or something similar) the ordering can be performed in the database rather than in LINQ to Objects.