I’m trying to do something I’m not sure LINQ can do -but let’s try!
I have 2 classes; one is a list structure for the other:
public class1 {
public int id {get; set;}
public string title {get; set;}
public List<class2> subcat {get; set;}
}
public class2 {
public int Value {get; set;}
public string Text {get; set;}
}
Is it possible to fill such structure with LINQ? Something like:
return (from r in results
from sub in subresults.Where(sub => sub.id == r.subid).DefaultIfEmpty()
select new class1 {
id = r.id,
title = r.title,
subcat = [GET TWO COLUMNS FROM 'SUB' INTO THIS]
}).ToList()
Is this possible? I’d hate to have to build them manually by using nested loops, etc.
Thanks in advance!
Is this what you need?