LINQ,Skip,OrderBy和SQL Server 2000 [英] LINQ, Skip, OrderBy, and SQL Server 2000

查看:92
本文介绍了LINQ,Skip,OrderBy和SQL Server 2000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问通过使用LINQ to SQL自动生成的数据上下文对象. SQL数据库是一个SQL Server 2000框.我正在使用的类是SQL视图.我有一个与此类似的声明:

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);

但是,当Skip的值不为0时,会出现此错误:

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

此提供程序仅在返回包含所有标识列的实体或投影的有序查询上才支持Skip(),其中该查询是单表(非联接)查询,或者是不同,除,相交,或联合(不是Concat)操作.

我认为在DateCompleted和LineItemId之间,行将是唯一的,但是随后又弹出了.这与视图有关吗?如果是这样,我该如何解决这个问题?

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?

推荐答案

我相信它的意思是,如果您在OrderDetails表上没有标识列,则需要在其中添加.Distinct()或提到的其他运营商.

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.

这篇关于LINQ,Skip,OrderBy和SQL Server 2000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆