VB.NET 的 LINQ 中 ORDERBY 的语法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/910762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:14:10 来源:igfitidea点击:
What's the syntax for ORDERBY in VB.NET's LINQ?
提问by Mehrdad Afshari
I'm new to Linq, what's the syntax for order by in VB?
我是 Linq 的新手,VB 中 order by 的语法是什么?
Dim cxt As New datContext
Dim qry = (From lst In cxt.zipcodes _
Select lst.state).Distinct
qry = qry.OrderBy()
my simple SQL statement will be like this:
我的简单 SQL 语句将是这样的:
Select distinct state from zipcodes
order by State
回答by Mehrdad Afshari
qry = qry.OrderBy(Function(obj) obj.PropertyToSortBy)
回答by Meta-Knight
Alternative syntax for your query (cleaner IMO):
查询的替代语法(更干净的 IMO):
Dim qry = From lst In cxt.zipcodes _
Select lst.state Distinct _
Order By state
回答by Wesam
Dim cxt As New datContext
Dim qry = (From lst In cxt.zipcodes OrderBy lst.state).Distinct.tolist
Dim statelst = qry.Select(Function(o) o.state).ToList