下面的代碼:跳過並採取:EF 4.1中的OFFSET LIMIT的有效方法?
using (var db = new Entities())
{
db.Blogs.First().Posts.Skip(10).Take(5).ToList();
}
將生成以下SQL:
-- statement #1
SELECT TOP (1) [c].[Id] AS [Id],
[c].[Title] AS [Title],
[c].[Subtitle] AS [Subtitle],
[c].[AllowsComments] AS [AllowsComments],
[c].[CreatedAt] AS [CreatedAt]
FROM [dbo].[Blogs] AS [c]
-- statement #2
SELECT [Extent1].[Id] AS [Id],
[Extent1].[Title] AS [Title],
[Extent1].[Text] AS [Text],
[Extent1].[PostedAt] AS [PostedAt],
[Extent1].[BlogId] AS [BlogId],
[Extent1].[UserId] AS [UserId]
FROM [dbo].[Posts] AS [Extent1]
WHERE [Extent1].[BlogId] = 1 /* @EntityKeyValue1 */
(從http://ayende.com/blog/4351/nhibernate-vs-entity-framework-4-0)
NB的跳躍和Take還沒有被翻譯成SQL導致所有職位從正在從數據庫加載的博客中,而不是我們需要的5個。
這看起來很危險,可怕的效率很低。令人難以置信的是,是什麼給了?
感謝您的回答,這是有幫助的,但我一直在尋找一個無EQL解決方案。我應該在問題中說明這一點。不過謝謝。 – Tom