有人可以帮助我有效地进行这个查询循环Linq查询吗?我把它加载到吗?TreeView因此,每个项目都必须附加。它也非常低效。延迟加载项目不起作用。事实上,此查询比应该查询更多地访问数据库6 M% W2 r# {9 t2 B t3 X( p/ w
public IQueryable GetTopLevelData(Guid agentGuid,int year) var clients = from client in ObjectContext.Clients join cbc in ObjectContext.Client_Bucket_Client on client.Client_GUID equals cbc.Client_GUID join acb in ObjectContext.Agent_Client_Bucket on cbc.Client_Bucket_GUID equals acb.Client_Bucket_GUID where acb.Agent_GUID == agentGuid select client; foreach (Client c in clients) var transactions = ObjectContext.Transactions.Where(t => t.Client_GUID == c.Client_GUID && t.Year == year); foreach (Transaction t in transactions) t.Forms.Attach(ObjectContext.Forms.Where(f => f.Transaction_GUID == t.Transaction_GUID && f.Year == year)); //.OrderByDescending(fo => fo.Create_Date)); c.Transactions.Attach(transactions); return clients; , K" E) I `5 @+ N" Y解决方案: