ienumerable vs iqueryable异常

This article won’t go into what these interfaces are, or the differences between them. For that, read this article for a good introduction.

本文将不讨论这些接口是什么或它们之间的区别。 为此,请阅读本文以获得良好的介绍。

Instead, I’ll show you an example of an Exception you can get from IQueryable but not from IEnumerable, for the exact same query.

相反,我将向您展示一个Exception的示例,您可以从IQueryable而不是IEnumerable那里获得完全相同的查询。

呼叫跳过(-x) (Calling Skip(-x))

Have a look at this code:

看一下这段代码:

IEnumerable<int> ids = GetIds();

IEnumerable<int> ids = GetIds();

ids.Skip(-4);

ids.Skip(-4);

This works fine.

这很好。

例外 (The Exception)

However, the following will throw an Exception:

但是,以下内容将引发Exception

IQueryable<int> ids = GetIds();

IQueryable<int> ids = GetIds();

ids.Skip(-4);

ids.Skip(-4);

错误讯息 (The Error Message)

The offset specified in a OFFSET clause may not be negative.

OFFSET子句中指定的偏移量不能为负。

为什么? (Why?)

The reason for the error is because the IQueryable<int> creates the following SQL query:

错误的原因是因为IQueryable<int>创建以下SQL查询:

SELECT [p].[Id]
FROM [Ids] AS [p]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS

In SQL, offsetcan’t have a negative value.

在SQL中, offset不能为负值。

翻译自: https://medium.com/swlh/ienumerable-vs-iqueryable-exceptions-daa09ce4d1a6

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值