具有以下代码:实体linq查询导致选择两个表。 查询中提供了所有数据,但无法将结果分成两个列表。
public Tuple<List<sale>, List<product>> SearchProduct(int productId = -1, string searchProduct = "")
{
//ToDo: searchProduct not working...gives nothing
var companyId = DalSession.DalGetCurrentUser().Company_ID;
using (var entity = new secondsoftEntities())
{
var query = (from s in entity.sales
join p in entity.products on s.Product_ID equals p.ProductID
where productId > 0 ? s.Product_ID == productId : s.Company_ID == companyId
select new { s, p }).ToList();
if (!string.IsNullOrEmpty(searchProduct))
{
query = query.FindAll(x => x.p.Description.ToLower().Contains(searchProduct.ToLower()));
}
// split s as List<sale> and p as List<product> to tuple output
return Tuple.Create(new List<sale>(), new List<product>() );
}
}
在查询结果中,我看到了s和p,但是如何将它们作为具有属性的列表来确定它,以便我可以在元组中返回它们。
Thanx Dinand
答案 0 :(得分:4)
return Tuple.Create(query.Select(x => x.s).ToList(),
query.Select(x => x.p).ToList());