linq的多表查询
public class P_type { public int p_type_id { get; set; } public int parent_id { get; set; } } public class Products { public int pid { get; set; } public int p_type_id { get; set; } } static void Main(string[] args) { List<P_type> list_P_type = new List<P_type>() { new P_type(){p_type_id=1,parent_id=0}, new P_type(){p_type_id=2,parent_id=1}, new P_type(){p_type_id=3,parent_id=1}, }; List<Products> list_Products = new List<Products>() { new Products(){p_type_id=2,pid=1}, new Products(){p_type_id=2,pid=2}, new Products(){p_type_id=3,pid=3}, new Products(){p_type_id=1,pid=4}, }; //如何查询list_Products中的pid 在list_P_type中parent_id为1的p_type_id //我都不知道怎么描述了..直接来个SQL.. //select pid from list_Products where list_Products.p_type_id in //(select p_type_id from list_P_type where parent_id=1) var one = from a in list_P_type where a.p_type_id in (from b in list_P_type where b.parent_id==1 select b.p_type_id) select a.pid; //不能这样写啊- -0 }
var one = from a in list_Products let t= list_P_type.Where(x=>x.parent_id == 1).Select(x=>x.p_type_id) where t.Contains(a.p_type_id) select a;
var one = list_Products.Where(a=>list_P_type.Where(x=>x.parent_id == 1).Select(x=>x.p_type_id).Contains(a.p_type_id));
var two = list_P_type.Where(x => x.parent_id == 1).Join(list_Products, p => p.p_type_id, p => p.p_type_id, (p_type, p_product) => p_product);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2009-05-08 无火不进房间回家程序及说明(广茂达灭火机器人)
2009-05-08 广茂达机器人灭火程序(纯C语言版)
2007-05-08 070508_设置上次考试_考生管理_成绩批量录入