New in linq for objects trying to figure this out. I have the following tables:
Customer: Cust_Id, Name
Orders: Order_Id
CustomerOrders: Cust_Id, Order_Id
I have a class like:
public class Customers { public List<Row> Rows { get; set; } public Customers() { Rows = new List<Row>(); } public class Row { public int Key { get; set; } public string Name { get; set; } public List<string> Order_Ids { get; set; } } }
The Linq query is as follows:
var query = from c in context.Customer select new Customers.Row { Key = c.Cust_Id, Name = c.Name, Order_IDs = List<string>( ?? ) }; foreach (var row in query) { Customers.Rows.Add(row); } var serializer = new JavaScriptSerializer(); return serializer.Serialize(Customers);
Where am I ??? can I use a subquery or something to get the Order_Id list from the CustomerOrders table? Right now, I can only think to go through the Customers table after filling it out, and then query the DB again to get each Order Id array for each Client.
source share