0

下面是我要转换为拉姆达查询的例子:如何将sql限制查询转换为linq 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 
+0

您可以使用'拿(5)' – Pawel

回答

1
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); 
0
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);