我有 2 张桌子:
- PK的用户数据
UserId
- 带有FK的用户订单
UserID
我想做 LINQ 查询,给我一个用户列表,其中成员是用户订单列表。
我试过了:
var myNestedData = (from ub in db.Users
join ah in db.UsersOrders on ub.UserId equals ah.UserId
into joined
from j in joined.DefaultIfEmpty()
group j by new { ub.UserId, ub.UserName, ub.UserPhone, ub.Approved } into grouped
where grouped.Key.Approved == true
select new
{
UserId= grouped.Key.UserId,
UserName = grouped.Key.UserName,
UserPhone = grouped.Key.UserPhone,
Orders = grouped
}).ToList();
问题是我进入Orders
了一个Object<a,UsersOrders>
我没想到的内部。
这是在性能方面接近解决方案的正确方法吗?