Entity Framewrok 7beta7 in different versions of SQL Server Automatic Component page SQL statement issues

Source: Internet
Author: User

In EF, it is convenient to use LINQ for paging, if we have an EMP table with the following structure:

public class Emp    {        [Key] public        Guid No {get; set;}        public int Age {get; set;}        [Required]        [Stringlength ()]        public string Name {get; set;}    }

If we are paging, we generally use the skip and take methods, where the simplest line of code is as follows:

MContext.Emp.OrderBy (emp = EMP). Name). Skip (6). Take (3);

If we are using EF6, when using SQL Server R2 and earlier databases, the following SQL statements are generated automatically:

SELECT TOP (3)     [extent1].[ No] as [no],     [extent1].[ Age] as [age],     [extent1].[ Name] as [name] from    (SELECT [extent1].[ No] as [no], [Extent1]. [Age] As [age], [Extent1]. [Name] As [Name], Row_number () over (ORDER by [extent1].[ Name] ASC) as [row_number] from        [dbo].[ EMP] as [Extent1]    ) as  [Extent1]    WHERE [extent1].[ Row_number] > 6    ORDER by [extent1].[ Name] ASC

If we are using EF6, when using SQL Server 2012 or 2014 databases, the following SQL statements are generated automatically:

SELECT     [extent1].[ No] as [no],     [extent1].[ Age] as [age],     [extent1].[ Name] as [name] from    [dbo].[ EMP] as [Extent1]    ORDER by [extent1].[ Name] ASC    

Because in SQL server 2012 and later databases, there is a higher performance paging method that uses offset ROWS FETCH NEXT rows only keywords, EF automatically generates matching SQL statements based on different versions of the database.

However, in Ef7beta7, perhaps the problem of a bug, always follow the method of fetch NEXT to generate, specifically as follows:

Using EF7BETA7, when using SQL Server R2 and earlier databases, the SQL statements are generated automatically as follows:

Select "EMP". " No "," emp "." Age "," emp "." Name "from                " emp "as" EMP "                ORDER by" EMP "." Name "                OFFSET 6 rows FETCH NEXT 3 rows only

Using EF7BETA7, when using a SQL Server 2012 or 2014 database, the following SQL statements are generated automatically:

Select "EMP". " No "," emp "." Age "," emp "." Name "from                " emp "as" EMP "                ORDER by" EMP "." Name "                OFFSET 6 rows FETCH NEXT 3 rows only

That is, the SQL statements generated by the two are the same, and there is a problem, and if you use LINQ for paging, you will get an error when using SQL Server R2 and earlier databases.

Briefly, this error should be generated in the EF7 source code in the Sqlserverquerysqlgenerator class and its affiliated classes, and hopefully the new version will solve the problem.

Entity Framewrok 7beta7 in different versions of SQL Server Automatic Component page SQL statement issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.