新的 linq 实体试图解决这个问题。我有以下表格:
Customer: Cust_Id, Name
Orders: Order_Id
CustomerOrders: Cust_Id, Order_Id
我有这样的课:
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; }
}
}
Linq 查询是这样的:
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);
我在哪里有'??',我可以使用子查询或其他东西Order_Id
从表中获取'sCustomerOrders
列表吗?现在,我只能考虑在Customers
表格填满后遍历表格,然后再次查询数据库以获取每个Order Id
客户的每个数组。