views:

305

answers:

2

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?

+2  A: 

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.

jarrett
I think this worked. Not sure though. Good suggestion!
Jason N. Gaylord
This did work. Nice "hack" to force Distinct() on the LINQ query.
Jason N. Gaylord
+3  A: 

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

Robert Harvey
I wish the error would be a bit more descriptive as to which issue it actually was. I'll have to dive in a bit more.
Jason N. Gaylord