Hi,
I Need to build the following through expression building:
VB.Net Code:
Dim Query = DBML.Clients_raw.SelectMany(Function(x As Database.clients_raw) x.IncomeAssessments)
I have done this:
VB.Net Code:
Dim Source = DBML.Clients_raw.AsQueryable
Dim TargetType = GetType(Database.IncomeAssessments)
Dim PropertyName = "IncomeAssessments"
Dim pSource = Expressions.Expression.Parameter(Source.ElementType)
Dim pSelector = Expressions.Expression.Parameter(Expressions.Expression.GetFuncType({Source.ElementType, GetType(IEnumerable(Of )).MakeGenericType(TargetType)}))
Dim Body = Expressions.Expression.PropertyOrField(pSource, PropertyName)
Dim Lambda = Expressions.Expression.Lambda(body, {pSource})
Dim Query = Source.Provider.CreateQuery(Expressions.Expression.Call(GetType(Queryable), NameOf(Queryable.SelectMany), {Source.ElementType, TargetType}, Source.Expression, Expressions.Expression.Quote(Lambda)))
... on the "Dim Query = ..." line above I get an InvalidOperationException: "No generic method 'SelectMany' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "
Any ideas?
Also ... There may of course be other errors :S ... I am not fluent in Expression building ... so any other help would be greatly appreciated
Thanks