Telerik:生成的SQL与示例项目不同

时间:2019-08-20 18:42:16

标签: entity-framework entity-framework-6 telerik-grid telerik-mvc

我正在使用Progress®KendoUI®Grid for ASP.NET MVC来显示类别表中的数据

Telerik示例应用程序和我的应用程序上生成的SQL代码不同 (请注意:两个项目中的Telerik(2017.1.223.545)和.net framework(4.5.1)的所有版本都相同)

为什么在我的应用程序中生成SQL的方式有所不同?我希望我的应用程序以相同的方式生成,以解决其他一些具有大量数据的项目中的性能问题。

我的申请:

public ActionResult ApplicationUserRole_Read([DataSourceRequest] DataSourceRequest request)
        {
            NorthwindEntities context = new NorthwindEntities();
            context.Categories.ToDataSourceResult(request);
            return Json("nothing");                  
        }

我的应用程序(生成的SQL):

2019-08-20 12:46:22,320 [54] INFO RollingFileDBAppender - SELECT 
    [Extent1].[CategoryID] AS [CategoryID], 
    [Extent1].[CategoryName] AS [CategoryName], 
    [Extent1].[Description] AS [Description], 
    [Extent1].[Picture] AS [Picture]
    FROM [dbo].[Categories] AS [Extent1]
    ORDER BY [Extent1].[CategoryID] ASC
    OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY 

示例:

public ActionResult Paging_Categories([DataSourceRequest] DataSourceRequest request)
        {
            var northwind = new SampleEntities();
            northwind.Categories.ToDataSourceResult(request);
            return Json("nothing");
        }

示例(生成的SQL):

2019-08-20 12:19:10,952 [26] INFO Kendo.Mvc.Examples.Models.SampleEntities+<>c line 25 - SELECT TOP (10) 
    [Extent1].[CategoryID] AS [CategoryID], 
    [Extent1].[CategoryName] AS [CategoryName], 
    [Extent1].[Description] AS [Description], 
    [Extent1].[Picture] AS [Picture]
    FROM ( SELECT [Extent1].[CategoryID] AS [CategoryID], [Extent1].[CategoryName] AS [CategoryName], [Extent1].[Description] AS [Description], [Extent1].[Picture] AS [Picture], row_number() OVER (ORDER BY [Extent1].[CategoryID] ASC) AS [row_number]
        FROM [dbo].[Categories] AS [Extent1]
    )  AS [Extent1]
    WHERE [Extent1].[row_number] > 0
    ORDER BY [Extent1].[CategoryID] ASC

1 个答案:

答案 0 :(得分:0)

两个项目中使用的实体框架不同。 由于某些原因,当我使用实体框架版本6.0.0时,在我们的Web应用程序中性能会更快

EF在不同版本中生成SQL的方式不同。

Entity Framework - 6.0.0

SELECT TOP (15) 
    [Extent1].[EmpId] AS [EmpId], 
    [Extent1].[Age] AS [Age], 
    [Extent1].[FirstName] AS [FirstName], 
    [Extent1].[Lastname] AS [Lastname]
    FROM ( SELECT [Extent1].[EmpId] AS [EmpId], [Extent1].[FirstName] AS [FirstName], [Extent1].[Lastname] AS [Lastname], [Extent1].[Age] AS [Age], row_number() OVER (ORDER BY [Extent1].[EmpId] ASC) AS [row_number]
        FROM [dbo].[Employees] AS [Extent1]
    )  AS [Extent1]
    WHERE [Extent1].[row_number] > 0
    ORDER BY [Extent1].[EmpId] ASC

Entity Framework - 6.1.3

SELECT 
    [Extent1].[EmpId] AS [EmpId], 
    [Extent1].[Age] AS [Age], 
    [Extent1].[FirstName] AS [FirstName], 
    [Extent1].[Lastname] AS [Lastname]
    FROM [dbo].[Employees] AS [Extent1]
    ORDER BY [Extent1].[EmpId] ASC
    OFFSET 0 ROWS FETCH NEXT 15 ROWS ONLY 

Entity Framework - 6.2.0

SELECT 
    [Extent1].[EmpId] AS [EmpId], 
    [Extent1].[Age] AS [Age], 
    [Extent1].[FirstName] AS [FirstName], 
    [Extent1].[Lastname] AS [Lastname]
    FROM [dbo].[Employees] AS [Extent1]
    ORDER BY row_number() OVER (ORDER BY [Extent1].[EmpId] ASC)
    OFFSET 0 ROWS FETCH NEXT 15 ROWS ONLY 
相关问题