我開發一個MVC應用程序返回。兩個查詢的加盟,並以列表形式
我現在用的是兩個查詢來獲取該記錄,我想從這些查詢的公共記錄。
我要回的數據列表中設置
像這樣
return Json(poList, JsonRequestBehavior.AllowGet);
我的兩個查詢是..
var poList = (from po in db.PurchaseOrders
where po.CompanyId == companyId && po.PartyId == partyId && (po.IsDeleted == false || po.IsDeleted == null)
select po into newPO
select new
{
Name = newPO.PONo,
Id = newPO.Id
});
//.ToList().OrderBy(e => e.Name);
var poList2 = (db.Employees.Where(x => x.Id == EmpID)
.SelectMany(x => x.Roles)
.SelectMany(x => x.Employees)
.Distinct()
.SelectMany(x => x.PurchaseOrders)
.Select(po => new { Name = po.PONo, Id = po.Id }));
var finalPO = from PO in poList.ToList().Union(poList2).ToList() select PO);
Try:var finalPO = from po in poList.ToList()。Union(poList2。ToList()) – CoffeeCode
Nop ...不工作... – bnil
閱讀此篇文章:http://stackoverflow.com/questions/4844660/differences-between-iqueryable-list-ienumerator/4844755它應該可以幫助你解決問題 –