Source
Run
<inst>.Source(<arg>)
<inst>.Source(<arg>.Query)
open Microsoft.FSharp.Quotations
let rec replace expr =
match expr with
| Patterns.Call(Some inst, mi, [arg]) when mi.Name = "Source" ->
let sourceMethod =
typeof<Linq.QueryBuilder>.GetMethods()
|> Seq.filter (fun mi ->
mi.Name = "Source" &&
mi.GetParameters().[0].ParameterType.Name = "IQueryable`1")
|> Seq.head
let sourceMethod =
sourceMethod.MakeGenericMethod
[| typeof<DowntimeEntity>; typeof<System.Linq.IQueryable> |]
let queryProp = typeof<T2>.GetProperty("Query")
Expr.Call(inst, sourceMethod, [ Expr.PropertyGet(arg, queryProp) ])
| ExprShape.ShapeCombination(o, args) ->
ExprShape.RebuildShapeCombination(o, List.map replace args)
| ExprShape.ShapeLambda(a, b) -> Expr.Lambda(a, replace b)
| ExprShape.ShapeVar(v) -> Expr.Var(v)
type QueryBuilder2() =
inherit Linq.QueryBuilder()
member __.Source (source: T2) = base.Source(source.Query)
member __.Run(e:Expr<Linq.QuerySource<'a, System.Linq.IQueryable>>) =
let e = Expr.Cast<Linq.QuerySource<'a, System.Linq.IQueryable>>(replace e.Raw)
base.Run(e)
repalce
replace