在两个选定列表中拆分linq join查询,并使用Tuple返回两个列表(Split linq join query in two selected lists and use Tuple to re

编程入门 行业动态 更新时间:2024-10-27 02:28:05
两个选定列表中拆分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());

更多推荐

本文发布于:2023-08-06 15:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   列表   列表中   join   linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!