LINQ TO SQL Null 查询 自己留用

来源:互联网 发布:演示demo制作软件 编辑:程序博客网 时间:2024/05/19 01:31

LINQ TO SQL   Null 查询

链接:http://blog.csdn.net/q107770540/article/details/7348384
[sql] view plaincopy
  1. SELECT *  
  2. FROM [Orders] AS [t0]  
  3. WHERE ([t0].[ShippedDate]) IS NULL  

 

v  方法一:

[csharp] view plaincopy
  1. from o in Orders  
  2. where o.ShippedDate==null  
  3. select o  

对应的Lamda表达式为:

[csharp] view plaincopy
  1. Orders  
  2.    .Where (o => (o.ShippedDate == (DateTime?)null))  

对应的SQL语句为:

[sql] view plaincopy
  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]  
  2. FROM [Orders] AS [t0]  
  3. WHERE [t0].[ShippedDate] IS NULL  

 

v  方法二:

[csharp] view plaincopy
  1. from o in Orders  
  2. where Nullable<DateTime>.Equals(o.ShippedDate,null)  
  3. select o  

对应的Lamda表达式为:

[csharp] view plaincopy
  1. Orders  
  2.    .Where (o => Object.Equals (o.ShippedDate, null))  

对应的SQL语句为:

[sql] view plaincopy
  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]  
  2. FROM [Orders] AS [t0]  
  3. WHERE [t0].[ShippedDate] IS NULL  

 

v  方法三:

[csharp] view plaincopy
  1. from o in Orders  
  2. where !o.ShippedDate.HasValue  
  3. select o  

对应的Lamda表达式为:

[csharp] view plaincopy
  1. Orders  
  2.    .Where (o => !(o.ShippedDate.HasValue))  

对应的SQL语句为:

[sql] view plaincopy
  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]  
  2. FROM [Orders] AS [t0]  
  3. WHERE NOT ([t0].[ShippedDate] IS NOT NULL)  

 

v  方法四:

[csharp] view plaincopy
  1. from o in Orders  
  2. where o.ShippedDate.Value==(DateTime?)null  
  3. select o  

对应的Lamda表达式为:

[csharp] view plaincopy
  1. Orders  
  2.    .Where (o => ((DateTime?)(o.ShippedDate.Value) == (DateTime?)null))  

 对应的SQL语句为:

[csharp] view plaincopy
  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]  
  2. FROM [Orders] AS [t0]  
  3. WHERE ([t0].[ShippedDate]) IS NULL  

 

v  方法五:

[csharp] view plaincopy
  1. from o in Orders  
  2. where  System.Data.Linq.SqlClient.SqlMethods.Equals(o.ShippedDate.Value,null)  
  3. select o  

对应的Lamda表达式为:

[csharp] view plaincopy
  1. Orders  
  2.     .Where (o => Object.Equals (o.ShippedDate.Value, null))  

对应的SQL语句为:

[sql] view plaincopy
  1. SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipReg
0 0
原创粉丝点击