linq subselect导致内存不足错误

时间:2014-09-17 21:54:22

标签: c# linq

版本字段在caluse导致内存不足错误的地方进行子选择。如果我删除它,那么查询工作正常。用户配置文件表有每个版本的多个条目,我只想在最终查询结果中使用最新的。关于如何使这个查询工作而不会出现内存不足错误的任何想法?

var x = (from p in userProfileRepo.All
                         join u1 in userRepo.All on p.USERID equals u1.USERID
                         join u2 in userRepo.All on p.LAST_MODIFIED_BY equals u2.USERID
                         join a in attrRepo.All on new { p.GROUP_NAME, p.PROFILE_NAME } equals new { a.GROUP_NAME, a.PROFILE_NAME } into attrJoin
                         from sub_a in attrJoin.DefaultIfEmpty()
                         where p.VERSION == (from up in userProfileRepo.All
                                             where up.GROUP_NAME == p.GROUP_NAME
                                             && up.PROFILE_NAME == p.PROFILE_NAME
                                             && up.USERID == p.USERID
                                             group up by up.VERSION into g
                                             select g.Max(t => t.VERSION)).FirstOrDefault()
                         select new
                         {
                             GroupName = p.GROUP_NAME,
                             Author = u1.FIRSTNAME + @"\" + u1.LASTNAME,
                             LastModifiedBy = u2.FIRSTNAME + @"\" + u2.LASTNAME,
                             ProfileName = p.PROFILE_NAME,
                             Version = p.VERSION,
                             GroupName2 = (sub_a == null ? "" : sub_a.GROUP_NAME),
                             AttrName = (sub_a == null ? "" : sub_a.ATTR_NAME),
                             AttrDisplayName = (sub_a == null ? "" : sub_a.ATTR_DISPLAY_NAME),
                             AttrValue = (sub_a == null ? "" : sub_a.ATTR_VALUE),
                             Visible = (sub_a == null ? "" : sub_a.VISIBLE)
                         }).ToList();

0 个答案:

没有答案