简体   繁体   English

如何在F#中对查询进行排序?

[英]How to sequence a query in F#?

So I have a query like this one 所以我有一个这样的查询

let query = 
    query {
        for person in people do
        select person
    }

And I'd like to have it sequenced . 而且我想对其进行排序

let sequence : seq<Person> = query

But I can't find any information on how to do it, maybe I've become bad at using search engines. 但是我找不到有关如何执行此操作的任何信息,也许我在使用搜索引擎方面变得很糟糕。

I'm getting unexpected type compiling expections using things like |> seq.ofList and ToList() . 我正在使用|> seq.ofListToList()类的东西来进行意外的类型编译期望。

The expression was expected to have the type seq<Person> but here has the type Generic.List<Person> . 该表达式应具有seq<Person>类型,但此处具有Generic.List<Person>类型。

The result of a query expression has type IQueryable<_> , which is a subtype of IEnumerable<_> (for which seq<_> is a synonym), so you can simply change the type: query表达式的结果具有IQueryable<_>类型,它是IEnumerable<_>的子类型(对于seq<_>是同义词),因此您可以简单地更改类型:

let mySeq : seq<_> = myQuery

Or, if you want to avoid a type annotation, use the built-in seq function , which does the same thing: 或者,如果要避免类型注释,请使用内置的seq函数 ,该函数执行相同的操作:

let mySeq = seq myQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM