Results 1 to 2 of 2

Thread: Expression Building

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Expression Building

    Hi,

    I Need to build the following through expression building:

    VB.Net Code:
    1. Dim Query = DBML.Clients_raw.SelectMany(Function(x As Database.clients_raw) x.IncomeAssessments)

    I have done this:
    VB.Net Code:
    1. Dim Source = DBML.Clients_raw.AsQueryable
    2. Dim TargetType = GetType(Database.IncomeAssessments)
    3. Dim PropertyName = "IncomeAssessments"
    4.  
    5. Dim pSource = Expressions.Expression.Parameter(Source.ElementType)
    6. Dim pSelector = Expressions.Expression.Parameter(Expressions.Expression.GetFuncType({Source.ElementType, GetType(IEnumerable(Of )).MakeGenericType(TargetType)}))
    7. Dim Body = Expressions.Expression.PropertyOrField(pSource, PropertyName)
    8. Dim Lambda = Expressions.Expression.Lambda(body, {pSource})
    9. 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

  2. #2

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Expression Building

    OK...
    Figured it out

    Dim Body = Expressions.Expression.Convert(Expressions.Expression.PropertyOrField(pSource, PropertyName), GetType(IEnumerable(Of )).MakeGenericType(TargetType))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width