C#, linq to sql, 为嘛single生成的sql 是top (2)而不是top (1)
2012-04-20 19:46:38 +08:00
avatasia
SELECT TOP (2) [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name], [Extent1].[Url] AS [Url], [Extent1].[ParentId] AS [ParentId] FROM [dbo].[MenuItem] AS [Extent1] WHERE [Extent1].[ParentId] IS NULL
@Ricepig single 是取唯一的一个,first是取多个中的第一个,所以single要做多于1的判断
thereisnoif
2012-04-25 10:49:56 +08:00
@avatasia 很奇怪啊,我确实用sql profiler看了,是没有top的。。。 难道跟Linq版本有关,我是4.0; C#查询是: var ret = App_Case_Alls.Single(c => c.Case_type == 1); Console.Write(ret);
sql profilerie截到的sql是:
exec sp_executesql N'SELECT [t0].[case_id] AS [Case_id], [t0].[case_type] AS [Case_type], [t0].[req_no] AS [Req_no] FROM [app_Case_All] AS [t0] WHERE [t0].[case_type] = @p0',N'@p0 int',@p0=1