LINQ、Skip、OrderBy 和 SQL Server 2000

发布于 2024-08-11 17:13:46 字数 562 浏览 3 评论 0原文

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

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

但是,当 Skip 的值不是 0 时,我收到此错误:

此提供程序仅支持 Skip() 有序查询返回包含所有标识列的实体或投影,其中查询是单表(非连接)查询,或者是 Distinct、Except、Intersect 或 Union(非 Concat)操作。

我认为在 DateCompleted 和 LineItemId 之间,行将是独一无二的,但这个问题又出现了。这和这个观点有关系吗?如果是这样,我该如何规避这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-08-18 17:13:46

SQL Server 2000 缺少一些 Linq 必须绕过的“管道”才能执行 Skip 和 Take 功能。这极大地限制了您在 SQL Server 2000 中使用这些函数的条件。

请确保您在 _context.OrderDetails 中包含 Identity 列,并且满足中所述的所有其他条件错误消息。

当然,您始终可以升级到 SQL Server 2005 或更高版本。 :)

更多信息请参见:http://msdn.microsoft.com/en-我们/library/bb386988.aspx

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

仅冇旳回忆 2024-08-18 17:13:46

我相信它所说的是,如果您在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文