Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Column in Linq query after migration to 2.0 #10570

Closed
sylvaincaillot opened this issue Dec 15, 2017 · 4 comments
Closed

Invalid Column in Linq query after migration to 2.0 #10570

sylvaincaillot opened this issue Dec 15, 2017 · 4 comments

Comments

@sylvaincaillot
Copy link

sylvaincaillot commented Dec 15, 2017

I just updated my API application to ASP.Net Core 2.0 as well as EF Core accordingly.

The following query used to work fine before:

IList<myDTO> allRecords = _context.myModel                               
                                .Select(item => new myDTO()
                                {
                                   recordId = item.myId,                                   
                                    recordName = item.myName                                  
                                })
                                .OrderBy(o=>o.recordName)                                
                                .Skip(limit * (page - 1))
                                .Take(limit)
                                .ToList();

public class myModel
    {       
        [Key]       
        public int myId { get; set; }       
        public string myName { get; set; }       
    }

public class myDTO
    {      
        public int recordId { get; set; }      
        public string recordName { get; set; }      
    }

After the update I always get a

System.Data.SqlClient.SqlException: 'Invalid column name 'recordName '.'

Additional info

If i remove the OrderBy statement as:

IList<myDTO> allRecords = _context.myModel                               
                                .Select(item => new myDTO()
                                {
                                   recordId = item.myId,                                   
                                    recordName = item.myName                                  
                                })                                                             
                                .Skip(limit * (page - 1))
                                .Take(limit)
                                .ToList();

or the recordName field as :

 IList<myDTO> allRecords = _context.myModel                               
                                .Select(item => new myDTO()
                                {
                                   recordId = item.myId            
                                })
                                .OrderBy(o=>o.recordName)                                
                                .Skip(limit * (page - 1))
                                .Take(limit)
                                .ToList();

or the Skip statement as:

IList<myDTO> allRecords = _context.myModel                               
                                    .Select(item => new myDTO()
                                    {
                                       recordId = item.myId,                                   
                                        recordName = item.myName                                  
                                    })
                                    .OrderBy(o=>o.recordName)
                                    .Take(limit)
                                    .ToList();

The Linq query works.

Further technical details

EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.5.2)

@smitpatel
Copy link
Contributor

possible duplicate of #9535
are you using RowNumberPaging?

@sylvaincaillot
Copy link
Author

Thank you
Yes i am effectivelly using RowNumberPaging as I am using SQL Server 2008 R2:
optionsBuilder.UseSqlServer(_config["ConnectionStrings:XXX"], b => b.UseRowNumberForPaging());

It is really a blocking issue for me.

@ajcvickers
Copy link
Contributor

@sylvaincaillot If you are still using RowNumberForPaging, could you please comment on issue #13959 and let us know why?

@sylvaincaillot
Copy link
Author

sylvaincaillot commented Nov 14, 2018

Thank you @ajcvickers. You can get rid of RowNumberForPaging, I have migrated to SQL Server 2017.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants