Hello,
请问你的数据量大吗?如果不是很大的话,你可以用LINQ2Object:
using (DFDBEntities db = new DFDBEntities())
{
var result = db.Orders.ToList().Select(o => new { OID = o.OrderID, ODNames = string.Join(",", o.OrderDetails.Select(od => od.OrderDetailName)) }).ToList();
}
这种方式会把数据记录预先加载到内存中然后对内存中的数据库进行删选,这里主要用了string.Join这个函数,这个在Linq2Enities是不能被识别的。
或这用嵌套循环:
Foreach()//对父表循环
{
Foreach()//对子表循环
{
}
}
这个会多写点代码。
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.