博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LINQ系列:LINQ to SQL Where条件
阅读量:6207 次
发布时间:2019-06-21

本文共 1891 字,大约阅读时间需要 6 分钟。

1. 单一条件查询

var expr = context.Products    .Where(p => p.ProductName == "LINQ to SQL");
SELECT     [Extent1].[ProductID] AS [ProductID],     [Extent1].[CategoryID] AS [CategoryID],     [Extent1].[ProductName] AS [ProductName],     [Extent1].[UnitPrice] AS [UnitPrice],     [Extent1].[Discontinued] AS [Discontinued]    FROM [dbo].[Product] AS [Extent1]    WHERE N'LINQ to SQL' = [Extent1].[ProductName]

2. 组合条件查询

var expr = context.Products    .Where(p => p.ProductName == "LINQ to SQL" && p.UnitPrice > 10m);
SELECT     [Extent1].[ProductID] AS [ProductID],     [Extent1].[CategoryID] AS [CategoryID],     [Extent1].[ProductName] AS [ProductName],     [Extent1].[UnitPrice] AS [UnitPrice],     [Extent1].[Discontinued] AS [Discontinued]    FROM [dbo].[Product] AS [Extent1]    WHERE (N'LINQ to SQL' = [Extent1].[ProductName]) AND ([Extent1].[UnitPrice] > cast(10 as decimal(18)))

3. Like查询

var expr = from p in context.Products           where p.ProductName.StartsWith("LINQ")           select new { p.ProductID, p.ProductName };
SELECT     [Extent1].[ProductID] AS [ProductID],     [Extent1].[ProductName] AS [ProductName]    FROM [dbo].[Product] AS [Extent1]    WHERE [Extent1].[ProductName] LIKE N'LINQ%'
var expr = from p in context.Products           where p.ProductName.EndsWith("LINQ")           select new { p.ProductID, p.ProductName };
SELECT     [Extent1].[ProductID] AS [ProductID],     [Extent1].[ProductName] AS [ProductName]    FROM [dbo].[Product] AS [Extent1]    WHERE [Extent1].[ProductName] LIKE N'%LINQ'
var expr = from p in context.Products           where p.ProductName.Contains("LINQ")           select new { p.ProductID, p.ProductName };
SELECT     [Extent1].[ProductID] AS [ProductID],     [Extent1].[ProductName] AS [ProductName]    FROM [dbo].[Product] AS [Extent1]    WHERE [Extent1].[ProductName] LIKE N'%LINQ%'

 

转载于:https://www.cnblogs.com/libingql/p/4048520.html

你可能感兴趣的文章
我的第一程序语言python
查看>>
DHCP服务开启了,为什么老是网络冲突
查看>>
跳出多重循环 JS
查看>>
MySql 自动更新时间为当前时间
查看>>
Configuring Aggregated Ethernet Interfaces
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Asp.net页面和Html页面之间的关系
查看>>
[故障解决]Mysql爆出ERROR 1044 (42000)的错误怎么办?
查看>>
MySQL之数据库对象查看工具mysqlshow
查看>>
关于大学生玩网络游戏的调查问卷
查看>>
ubuntu安装nodejs
查看>>
数据类型之Integer与int
查看>>
转载:ASP.NET在后台代码实现个功能,根据选择提示用户是否继续执行操作
查看>>
[Angularjs]锚点操作服务$anchorScroll
查看>>
静态代理设计与动态代理设计
查看>>
uva-10152-乌龟排序
查看>>
ThreadLocal源码剖析
查看>>
每天一个linux命令(12):more命令
查看>>
奈奎斯特采样定理:
查看>>