关于Linq To Entity的排序问题
IQueryable.Where(e=>e.IsTrash==flag).ToList();IQueryable.Where(e=>e.IsTrash==flag).Or...
IQueryable.Where(e => e.IsTrash == flag).ToList();
IQueryable.Where(e => e.IsTrash == flag).OrderBy(e => e.Sort).ToList();
为什么一排序就会多SELECT一次,语句如下:
exec sp_executesql N'SELECT
[Project1].[RowID] AS [RowID],
[Project1].[Code] AS [Code],
[Project1].[Sort] AS [Sort],
FROM ( SELECT
[Extent1].[RowID] AS [RowID],
[Extent1].[Code] AS [Code],
[Extent1].[Sort] AS [Sort],
FROM [dbo].[Language] AS [Extent1]
WHERE [Extent1].[IsTrash] = @p__linq__0
) AS [Project1]
ORDER BY [Project1].[Sort] ASC',N'@p__linq__0 bit',@p__linq__0=0
go
===========================================
如果参数直接写死,也没问题。
比如将布尔值参数flag直接写为false:
IQueryable.Where(e => e.IsTrash == false).OrderBy(e => e.Sort).ToList();
这样也只SELECT 1次 展开
IQueryable.Where(e => e.IsTrash == flag).OrderBy(e => e.Sort).ToList();
为什么一排序就会多SELECT一次,语句如下:
exec sp_executesql N'SELECT
[Project1].[RowID] AS [RowID],
[Project1].[Code] AS [Code],
[Project1].[Sort] AS [Sort],
FROM ( SELECT
[Extent1].[RowID] AS [RowID],
[Extent1].[Code] AS [Code],
[Extent1].[Sort] AS [Sort],
FROM [dbo].[Language] AS [Extent1]
WHERE [Extent1].[IsTrash] = @p__linq__0
) AS [Project1]
ORDER BY [Project1].[Sort] ASC',N'@p__linq__0 bit',@p__linq__0=0
go
===========================================
如果参数直接写死,也没问题。
比如将布尔值参数flag直接写为false:
IQueryable.Where(e => e.IsTrash == false).OrderBy(e => e.Sort).ToList();
这样也只SELECT 1次 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询