子查询
描述:查询订单数超过5的顾客信息
查询句法:
|
var 子查询 = from c in ctx.Customers where (from o in ctx.Orders group o by o.CustomerID into o where o.Count() > 5 select o.Key).Contains(c.CustomerID) select c; |
in 操作
描述:查询指定城市中的客户
查询句法:
|
var in操作 = from c in ctx.Customers where new string[] { "Brandenburg", "Cowes", "Stavern" }.Contains(c.City) select c; |
Join
描述:内连接,没有分类的产品查询不到
查询句法:
|
var innerjoin = from p in ctx.Products join c in ctx.Categories on p.CategoryID equals c.CategoryID select p.ProductName; |
描述:外连接,没有分类的产品也能查询到
查询句法:
|
var leftjoin = from p in ctx.Products join c in ctx.Categories on p.CategoryID equals c.CategoryID into pro from x in pro.DefaultIfEmpty() select p.ProductName; |
本文介绍使用LINQ进行不同类型的查询操作,包括子查询、IN操作及JOIN操作等,通过具体示例展示了如何筛选订单数量超过5的顾客信息、查找特定城市的客户以及产品与分类之间的内外连接查询。
136

被折叠的 条评论
为什么被折叠?



