原先根据需求要对数据进行两种筛选,起初写过滤条件,但是过滤后发现有的数据重叠。因此改为查询两次。
因为查询后返回的是两个相同的、匿名的 IQueryable ,最终的目的是想两个 类型结合成一个。
参考了:http://bbs.csdn.net/topics/310132452 #15楼的答案
var msg = (from m in dc.Messages where (m.OverTime > System.DateTime.Now && m.Status == 1) && (m.MessageTypeID == 0 || m.MessageTypeID == 1) select new { ID = m.MessageID, Company_Id = m.Company_Id, CompanyName = m.Company.CompanyName, Title = m.Content, UpdateTime = m.UpdateTime, returnType = "需求" }).Concat(from mm in dc.Messages where mm.OverTime > System.DateTime.Now && mm.Status == 1 && mm.MessageTypeID == 3 select new { ID = mm.MessageID, Company_Id = mm.Company_Id, CompanyName = mm.Company.CompanyName, Title = mm.Title, UpdateTime = mm.UpdateTime, returnType = "供应" }).OrderByDescending(oy => oy.UpdateTime).Take(iTop);
最终使用 Concat 来连接两个类型
var query_all = query1.Concat(query2);