I'm trying to convert a List of MyObject that I'm doing operation on by using LINQ and turning back to a list of MyObject.
public class Part
{
public string ID { get; set; }
public string DescFr { get; set; }
public string DescEng { get; set; }
public string PartNumber{ get; set; }
public Part(string strID, string strDescFr, string strDescEng, string strPartNumber)
{
this.ID = strID;
this.DescFr = strDescfr;
this.DescEng = strDescEng;
this.PartNumber= strPartNumber;
}
}
So in another class I use that class to create a list of Part objects via the database.
List<Part> lstParts = DB.Query.GetParts();
After that I'm grouping them by description
var lstGrouped = lstParts.GroupBy(x => x.DescrFr);
EDIT:
var lstGrouped = lstParts.GroupBy(x => x.PartNumber);
How can I convert back the lstGrouped back to List<Part>?
I have tried the ToList() method and cast it to List<Part>, it does not work, giving me an cast error:
enable to cast object of type