工具:LinqPad
要求:关键字过滤,时间过滤,分页。
(from e in EventLogs
join l in Events on e.Eventid equals l.EventID
where l.NeedACK==1
&& e.EventTime>DateTime.Parse("2012-08-05 11:14:52" )
&& e.EventTime<DateTime.Parse("2012-08-06 11:14:52")
&& e.Descript.Contains("A1")
orderby e.EventTime descending
select e).Skip(20).Take(10)
join l in Events on e.Eventid equals l.EventID
where l.NeedACK==1
&& e.EventTime>DateTime.Parse("2012-08-05 11:14:52" )
&& e.EventTime<DateTime.Parse("2012-08-06 11:14:52")
&& e.Descript.Contains("A1")
orderby e.EventTime descending
select e).Skip(20).Take(10)
LinqPad生成的T-SQL
-- Region Parameters
DECLARE @p0 Int = 1
DECLARE @p1 DateTime = '2012-08-05 11:14:52.000'
DECLARE @p2 DateTime = '2012-08-06 11:14:52.000'
DECLARE @p3 VarChar(1000) = '%A1%'
DECLARE @p4 Int = 20
DECLARE @p5 Int = 10
-- EndRegion
SELECT [t2].*
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[EventTime] DESC) AS [ROW_NUMBER], [t0].*
FROM [EventLog] AS [t0]
INNER JOIN [Events] AS [t1] ON [t0].[eventid] = [t1].[EventID]
WHERE ([t1].[needACK] = @p0) AND ([t0].[EventTime] > @p1) AND ([t0].[EventTime] < @p2) AND ([t0].[descript] LIKE @p3)
) AS [t2]
WHERE [t2].[ROW_NUMBER] BETWEEN @p4 + 1 AND @p4 + @p5
ORDER BY [t2].[ROW_NUMBER]
DECLARE @p0 Int = 1
DECLARE @p1 DateTime = '2012-08-05 11:14:52.000'
DECLARE @p2 DateTime = '2012-08-06 11:14:52.000'
DECLARE @p3 VarChar(1000) = '%A1%'
DECLARE @p4 Int = 20
DECLARE @p5 Int = 10
-- EndRegion
SELECT [t2].*
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[EventTime] DESC) AS [ROW_NUMBER], [t0].*
FROM [EventLog] AS [t0]
INNER JOIN [Events] AS [t1] ON [t0].[eventid] = [t1].[EventID]
WHERE ([t1].[needACK] = @p0) AND ([t0].[EventTime] > @p1) AND ([t0].[EventTime] < @p2) AND ([t0].[descript] LIKE @p3)
) AS [t2]
WHERE [t2].[ROW_NUMBER] BETWEEN @p4 + 1 AND @p4 + @p5
ORDER BY [t2].[ROW_NUMBER]