The answer will depend on what you're querying. Many data sources will expose something like a data context that enables running queries in different ways, but this isn't exposed directly on the IQueryable
type (and is therefore not something that you can do directly with the result of a query { ... }
expression.
As an example, if your foo
is a LINQ-to-SQL Table<Foo>
, then you can do something like this:
let queryExample name =
let q =
query { for f in foo do
where (f.name = name)
select f.name }
let cmd = foo.Context.GetCommand(q)
async {
let! reader = Async.AwaitTask (cmd.ExecuteReaderAsync())
return foo.Context.Translate<Foo>(reader)
}
This will return an Async<seq<Foo>>
. If you'll be running lots of queries like this, then it's easy to extract the meat of this into a reusable mechanism.