Open lucasteles opened 1 year ago
You can make the single table query working like this
type EFQueryBuilder() =
member _.For (source: IQueryable<'T>, body: 'T -> _) : IQueryable<'T> =
source
[<CustomOperation("select",MaintainsVariableSpace=true,AllowIntoPattern=true)>]
member _.Select (source, [<ProjectionParameter>] projection: Expression<Func<'T,'U>>) =
Queryable.Select(source, projection)
[<CustomOperation("where",MaintainsVariableSpace=true)>]
member _.Where (source, [<ProjectionParameter>] projection: Expression<Func<'T,_>>) =
Queryable.Where(source, projection)
[<CustomOperation("orderBy",MaintainsVariableSpace=true)>]
member _.OrderBy (source, [<ProjectionParameter>] keySelector: Expression<Func<'T,_>>) =
Queryable.OrderBy(source, keySelector)
member _.Yield (value: 't) =
Seq.singleton value
EFQueryBuilder() {
for i in db.Blogs do
where (i.BlogId > 1)
select $"{i}"
}
Looks like today to create custom computation expressions it is required that the bind function to be an
FSharpFunc
, allowing it to beExpression<>
orFunc<>
could be very handy for CLR interopAn example is creating a query builder for EF
And actually the custom operator with
ProjectionParameter
recognize the expression as the same as any functionPros and Cons
The advantages of making this adjustment to F# are :
The disadvantages of making this adjustment to F# are:
Extra information
Estimated cost (XS, S, M, L, XL, XXL): ?
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.