This code is meant to execute a F# Query against an EF DbContext
, using quotations to isolate the repeating
let db() = serviceProvider.CreateScope().ServiceProvider.GetRequiredService<IMyDbContext>()
let usingDb f = db() |> f
let fff qq : IPounceDbContext -> IQueryable<_> =
let a = LeafExpressionConverter.QuotationToLambdaExpression(qq)
let b = a.Compile()
b
let ff qq = usingDb (fun db -> ((fff qq)(db)).SingleAsync())
member __.ReadRepo(userEmail: string, key: string) =
<@ fun (db: IMyDbContext) -> query {
for userRepo in db.UserRepos do
join user in db.Users on (userRepo.UserId = user.UserId)
where (user.Email = userEmail && userRepo.Key = key)
select userRepo.Value } @> |> ff
When calling
let a = LeafExpressionConverter.QuotationToLambdaExpression(qq)
at run time, the following exception is thrown
InvalidCastException: Unable to cast object of type
‘System.Linq.Expressions.MethodCallExpression1’ to type
‘System.Linq.Expressions.Expression1[Microsoft.FSharp.Core.FSharpFunc
2[{OMITTED NAMESPACE}.IMyDbContext,System.Linq.IQueryable`1[System.String]]]’.”)
What is the problem?