You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can extend QueryBuilder with custom operators, e.g.:
openSystemopenSystem.LinqopenMicrosoft.FSharp.Linq[<AutoOpen>]moduleAsyncQueryBuilderOperations =typeQueryBuilderwith/// A query operator that returns the number of selected elements.[<CustomOperation("countAsync")>]memberx.CountAsync(source:Linq.QuerySource<'T,'Q>)=
source.Source.AsQueryable()|> getCountAsync
/// A query operator that selects the first element from those selected so far.[<CustomOperation("headAsync")>]memberx.HeadAsync(source:Linq.QuerySource<'T,'Q>)=
source.Source.AsQueryable()|> getHeadAsync
/// A query operator that selects the first element of those selected so far, or a default value if the sequence contains no elements.[<CustomOperation("headOrDefaultAsync")>]memberx.HeadOrDefaultAsync(source:Linq.QuerySource<'T,'Q>)=async{let!res= source.Source.AsQueryable()|> getTryHeadAsync
returnmatch res with Some x -> x | None -> Unchecked.defaultof<'T>}
Then I can actually use them like:
[<Test >]let``simple select with countAsync``()=letdc= sql.GetDataContext()letquery=
query {for cust in dc.Main.Customers do
select cust.CustomerId
countAsync
}|> Async.RunSynchronously
Assert.AreEqual(91, query)
But the problem is that F# LINQ Query translator doesn't like them on runtime:
System.NotSupportedException : This is not a valid query expression. The
method 'Microsoft.FSharp.Control.FSharpAsync`1[System.Int32] QueryBuilder.CountAsync
[String,Object](Microsoft.FSharp.Linq.QueryBuilder, Microsoft.FSharp.Linq.QuerySource`2
[System.String,System.Object])' was used in a query but is not recognized by the F#-to-LINQ query
translator. Check the specification of permitted queries and consider moving some of the operations
out of the query expression
at Microsoft.FSharp.Linq.QueryModule.TransInner(CanEliminate canElim, Boolean check, FSharpExpr immutQuery)
at Microsoft.FSharp.Linq.QueryModule.TransInnerAndCommit(CanEliminate canElim, Boolean check, FSharpExpr x)
at Microsoft.FSharp.Linq.QueryModule.TransInnerWithFinalConsume(CanEliminate canElim, FSharpExpr immutSource)
at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedInner(CanEliminate canElim, FSharpExpr queryProducingSequence)
at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedOuter(CanEliminate canElim, FSharpExpr tm)
at Microsoft.FSharp.Linq.QueryModule.clo@1737-1.Microsoft-FSharp-Linq-ForwardDeclarations-IQueryMethods-Execute[a,b](FSharpExpr`1 )
at QueryTests.simple select with countAsync() in C:\git\SQLProvider\tests\SqlProvider.Tests\QueryTests.fs:line 66
I can extend QueryBuilder with custom operators, e.g.:
Then I can actually use them like:
But the problem is that F# LINQ Query translator doesn't like them on runtime:
The problem is this file:
https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Core/Query.fs
raise ... unsupportedQueryConstruct
The text was updated successfully, but these errors were encountered: