我正在使用 EF4.0,我写了一个查询:
var query = context.Post.Where(p => p.Id == postId).SingleOrDefault();
我只需要此查询中的一篇文章。我认为 SingleOrDefault() 会生成“SELECT TOP(1) ...”,但是当我查看 SQL Profiler 时,它是:
exec sp_executesql N'SELECT TOP (2)
[Extent1].[Id] AS [Id],
[Extent1].[Title] AS [Title],
[Extent1].[Slug] AS [Slug],
[Extent1].[PubDate] AS [PubDate],
[Extent1].[PostContent] AS [PostContent],
[Extent1].[Author] AS [Author],
[Extent1].[CommentEnabled] AS [CommentEnabled],
[Extent1].[AttachmentId] AS [AttachmentId],
[Extent1].[IsPublished] AS [IsPublished],
[Extent1].[Hits] AS [Hits],
[Extent1].[CategoryId] AS [CategoryId]
FROM [dbo].[Post] AS [Extent1]
WHERE [Extent1].[Id] = @p__linq__0',N'@p__linq__0 uniqueidentifier',@p__linq__0='ECD9F3BE-3CA9-462E-AE79-2B28C8A16E32'
我想知道为什么 EF 会导致 SELECT TOP (2)?我只需要一个帖子。