如何将 sql 限制查询转换为 linq lambda?
How to convert sql limit query to linq lambda?
这是我要转换为 lambda 查询的示例:
SELECT TOP(5) Pbschedules.s_id, Pbschedules.date, Pbworth2.worth, Pbschedules.pb_id
FROM Pbschedules INNER JOIN Pbworth2 ON Pbschedules.pb_id = Pbworth2.pb_id
ORDER BY s_id desc
var query = database.Pbschedules// your starting point - table in the "from" statement
.Join(database.Pbworth2, // the source table of the inner join
pbs=> pbs.pb_id, // Select the primary key (the first part of the "on" clause in an sql "join" statement)
worth=> worth.pb_id, // Select the foreign key (the second part of the "on" clause)
(pbs, worth) => new { PbsID = pbs.s_id, Worth = worth.worth /*other columns*/ }) // selection
.OrderByDescending(x => x.s_id)
.Take(5);
var myData = (from valuesPbs in Pbschedules join valuesPbw in Pbworth2
on valuesPbs.pb_id equals valuesPbw.pb_id
orderby valuesPbs.s_id descending
select valuesPbs
).Take(5);
这是我要转换为 lambda 查询的示例:
SELECT TOP(5) Pbschedules.s_id, Pbschedules.date, Pbworth2.worth, Pbschedules.pb_id
FROM Pbschedules INNER JOIN Pbworth2 ON Pbschedules.pb_id = Pbworth2.pb_id
ORDER BY s_id desc
var query = database.Pbschedules// your starting point - table in the "from" statement
.Join(database.Pbworth2, // the source table of the inner join
pbs=> pbs.pb_id, // Select the primary key (the first part of the "on" clause in an sql "join" statement)
worth=> worth.pb_id, // Select the foreign key (the second part of the "on" clause)
(pbs, worth) => new { PbsID = pbs.s_id, Worth = worth.worth /*other columns*/ }) // selection
.OrderByDescending(x => x.s_id)
.Take(5);
var myData = (from valuesPbs in Pbschedules join valuesPbw in Pbworth2
on valuesPbs.pb_id equals valuesPbw.pb_id
orderby valuesPbs.s_id descending
select valuesPbs
).Take(5);