用于执行“Between”的 Linq 表达式
在 SQL 中,您可以编写一个查询,在“nvachar”类型的列上执行 Between,并简单地返回指定的最小值和最大值之间的所有行。
例如,
Table (Id:Int, Name:nvarchar):
Contents:
1, Annie
2, Bill
3, Frank
4, Phil
5, Ted
Select * where Name Between 'Frank' and 'Ted'
Should return Frank, Phil, and Ted.
有没有办法使用 linq 执行此操作,或者我是否必须创建自定义查询并执行它?我见过的唯一例子涉及日期或整数,这使得它变得非常容易(可以使用比较运算符,如<,>等)。
In SQL you have the ability to write a query that executes a between on a column that is of type 'nvachar' and simply returns to you all the rows that are between the min and max values specified.
For Example,
Table (Id:Int, Name:nvarchar):
Contents:
1, Annie
2, Bill
3, Frank
4, Phil
5, Ted
Select * where Name Between 'Frank' and 'Ted'
Should return Frank, Phil, and Ted.
Is there a way to do this with linq or am I going to have to create a custom query and execute it? The only examples I have seen involve dates or integers which make it very easy (can use the comparison operators like <, > etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
CompareTo
来代替:使用
>
和<
来排除(即排除 Frank 和 Ted)。基本上它与使用
<
和>
相同,但使用方法:)You'd use
CompareTo
instead:Use
>
and<
to be exclusive (i.e. to exclude Frank and Ted).Basically it's the same as using
<
and>
, but with methods :)