在两个选定列表中拆分linq join查询,并使用Tuple返回两个列表(Split linq join query in two selected lists and use Tuple to return the two lists)
具有以下代码:实体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
Have the following code: a entity linq query results in a select of two tables. All data is available in the query, but can't get the result to split into two lists.
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>() ); } }In the query result I see s and p, but how the exact them as a list with there properties in it so I can return them in Tuple.
Thanx Dinand
最满意答案
return Tuple.Create(query.Select(x => x.s).ToList(), query.Select(x => x.p).ToList()); return Tuple.Create(query.Select(x => x.s).ToList(), query.Select(x => x.p).ToList());更多推荐
发布评论