linq两个list合并查询

wozaiztam 2013-12-23 10:19:24
 IList<ts_dynamic> dynamicList = null;
var allDynamic = (new ts_dynamicService()).GetAllDynamicByCompanyId(companyId);
if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))
dynamicList = allDynamic.Where(x => x.shareType == 4 && x.shareObjectId == userId)
.Select(y => new ts_dynamic { hirerId = y.hirerId, contentId = y.contentId }).ToList();//@我的动态
else if (string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))
dynamicList = allDynamic.Select(y => new ts_dynamic { hirerId = y.hirerId, contentId = y.contentId }).ToList();
else
dynamicList = allDynamic.Where(x => x.shareType == 1 && x.shareObjectId == groupId)
.Select(y => new ts_dynamic { hirerId = y.hirerId, contentId = y.contentId }).ToList();//所在群组动态
//根据查询到的动态再去查附件
//上面代码已经取到动态表中的hirerId和contentId
//下面要根据上面的hirerId和contentId 去GetAllAttachByCompanyId取到的附件表中查询匹配的所有附件
var attachs = GetAllAttachByCompanyId(companyId).Where(x => x.hirerId==dynamicList//此处并没有dynamicList.hireId,但是数据库中是有的);



请问linq怎么写啊?
...全文
571 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wozaiztam 2013-12-25
  • 打赏
  • 举报
回复
没有人会吗?
Dotar 2013-12-25
  • 打赏
  • 举报
回复
var attachs = from GetAllAttachByCompanyId(companyId) in dynamicList where x => x.hirerId==dynamicList select new { 附件 = GetAllAttachByCompanyId(companyId).附件 }; foreach (var item in attachs) { Response.Write(item + "<br/>"); }
Andy__Huang 2013-12-25
  • 打赏
  • 举报
回复
先把两个list合并成一个新的list,再对这个新的list查询 如果不是这样做,那么只能关联查询。
Andy__Huang 2013-12-25
  • 打赏
  • 举报
回复
List<CourseBookingEDM> listbooking1 = BOSUtility.ConvertToCourseBookingEDM(indvlist);
List<CourseBookingEDM> listbooking2 = BOSUtility.ConvertToCourseBookingEDM(complist);
listbooking1.AddRange(listbooking2);
  • 打赏
  • 举报
回复
发到LinQ版面试试

8,494

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧