LINQ, Skip, OrderBy, and SQL Server 2000

若如初见. 提交于 2019-12-12 18:31:15

问题


I'm accessing a data context object that is auto-generated by using LINQ to SQL. The SQL database is a SQL Server 2000 box. The class I'm working with is a SQL View. I have a statement that is similar to this:

query = _context.OrderDetails
    .Where(w => w.Product == "TEST")
    .OrderBy(o => o.DateCompleted)
    .ThenBy(t => t.LineItemId)
    .Skip(startRowIndex) 
    .Take(maximumRows);

However, when the value of Skip is anything but 0, I get this error:

This provider supports Skip() only over ordered queries returning entities or projections that contain all identity columns, where the query is a single-table (non-join) query, or is a Distinct, Except, Intersect, or Union (not Concat) operation.

I'd think that between teh DateCompleted and LineItemId that the rows would be unique, but then again this pops up. Does it have to do with this being a view? If so, how can I circumvent this issue?


回答1:


I believe what it says is that if you don't have an identity column on the OrderDetails table then you need to add .Distinct() in there or one of the other operators mentioned.




回答2:


SQL Server 2000 has some missing "plumbing" that Linq has to get around in order to perform Skip and Take functions. This substantially restricts the conditions in which you can use these functions with SQL Server 2000.

Make sure you are including the Identity column in _context.OrderDetails, and that you are fulfilling all of the other conditions as stated in the error message.

Of course, you can always upgrade to SQL Server 2005 or later. :)

More info here: http://msdn.microsoft.com/en-us/library/bb386988.aspx



来源:https://stackoverflow.com/questions/1751232/linq-skip-orderby-and-sql-server-2000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!