我想在 sql server 2008 中检索最后 100 条插入的记录。
请更正我的代码。 表 testContext.testDetailRecords 中的 Pkey 是标识列。
var pkeys = (from tests in testContext.testDetailRecords
where tests.Pkey > (select max(tests.Pkey)-100 from testContext.testDetailRecords))
select tests.Pkey).ToList();
最佳答案
怎么样
var pkeys = testContext.testDetailRecords
.OrderByDescending(x => x.PKey)
.Take(100)
.Select(x => x.PKey);
这应该大致翻译成 SQL
SELECT TOP 100 PKey
FROM testDetailRecords
ORDER BY PKey DESC
关于c# - 在sql server中获取最后100条插入的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401769/