WHERE:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句。Where操作包括3种形式,分别为简单形式、关系条件形式、First()形式。下面分别用实例举例下:
1.简单形式:
var CityList =
from City in dc.DB_City
where City.Pid == 0
select City;
对应SQL语句:from City in dc.DB_City
where City.Pid == 0
select City;
SELECT [t0].[CityID], [t0].[Pid], [t0].[CityName], [t0].[IsVisible], [t0].[IsLastNode], [t0].[Order] AS [Order], [t0].[MetaID], [t0].[CityType], [t0].[ListName]
FROM [dbo].[DB_City] AS [t0]
WHERE [t0].[Pid] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
2.关系条件形式:FROM [dbo].[DB_City] AS [t0]
WHERE [t0].[Pid] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
var CityList =
from City in dc.DB_City
where City.Pid == 0 && City.IsVisible==true
select City;
对应SQL语句:from City in dc.DB_City
where City.Pid == 0 && City.IsVisible==true
select City;
SELECT [t0].[CityID], [t0].[Pid], [t0].[CityName], [t0].[IsVisible], [t0].[IsLastNode], [t0].[Order] AS [Order], [t0].[MetaID], [t0].[CityType], [t0].[ListName]
FROM [dbo].[DB_City] AS [t0]
WHERE ([t0].[Pid] = @p0) AND ([t0].[IsVisible] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
FROM [dbo].[DB_City] AS [t0]
WHERE ([t0].[Pid] = @p0) AND ([t0].[IsVisible] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
var CityList =
from City in dc.DB_City
where City.Pid == 0 || City.CityType == 2
select City;
对应SQL语句:from City in dc.DB_City
where City.Pid == 0 || City.CityType == 2
select City;
SELECT [t0].[CityID], [t0].[Pid], [t0].[CityName], [t0].[IsVisible], [t0].[IsLastNode], [t0].[Order] AS [Order], [t0].[MetaID], [t0].[CityType], [t0].[ListName]
FROM [dbo].[DB_City] AS [t0]
WHERE ([t0].[Pid] = @p0) OR ([t0].[CityType] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [2]
3.First形式:返回集合中的一个元素,其实质就是在SQL语句中加TOP (1)。FROM [dbo].[DB_City] AS [t0]
WHERE ([t0].[Pid] = @p0) OR ([t0].[CityType] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [2]
var CityList = dc.DB_City.First();
对应SQL语句:SELECT TOP (1) [t0].[CityID], [t0].[Pid], [t0].[CityName], [t0].[IsVisible], [t0].[IsLastNode], [t0].[Order] AS [Order], [t0].[MetaID], [t0].[CityType], [t0].[ListName]
FROM [dbo].[DB_City] AS [t0]
FROM [dbo].[DB_City] AS [t0]
var CityList = dc.DB_City.First(City=>City.Pid==0);
对应SQL语句:SELECT TOP (1) [t0].[CityID], [t0].[Pid], [t0].[CityName], [t0].[IsVisible], [t0].[IsLastNode], [t0].[Order] AS [Order], [t0].[MetaID], [t0].[CityType], [t0].[ListName]
FROM [dbo].[DB_City] AS [t0]
WHERE [t0].[Pid] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]
呵呵,今天就学习这点,明天继续抽空学习。FROM [dbo].[DB_City] AS [t0]
WHERE [t0].[Pid] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [0]