Linq Expression problem

Thread is closed for posting
2 posts, 0 answers
  1. steve
    steve avatar
    1 posts
    Member since:
    Feb 2011

    Posted 26 Feb 2011 Link to this post


    I am trying to do something along the lines of

    private static Expression<Func<Customer, string>> CreateSelectorExpression(string propertyName)
            var paramterExpression = Expression.Parameter(typeof(Customer));
            return (Expression<Func<Customer, string>>)Expression.Lambda(Expression.PropertyOrField(paramterExpression, propertyName), paramterExpression);

    When using this expression in a linq select against a LinqToEntitiesDomainService works prefectly

    When using it against an openaccessdomainservice it fails with a null reference exception.

    It took me ages to resolve this but in the end it only took a small change.  Changing

    var paramterExpression = Expression.Parameter(typeof(Customer));

    var paramterExpression = Expression.Parameter(typeof(Customer), "ANYTHING_HERE);

    allows the query to run successfuly.  Even putting "Param_0" which is what the first parameter constructor would use internally still works fine.  I thought this 2nd name parameter was purely used for debugging and printing purposes ?

    I think I have a fix which is fine but something doesn't feel quite right


    Steve Hayles

  2. PetarP
    PetarP avatar
    754 posts

    Posted 10 Mar 2011 Link to this post

    Hi steve,

     Indeed we have an internal problem when translating the Linq query in the way you have originally defined it and the workaround is the one you have employed yourself. There shouldn't be a problem to use the workaround as it does not limit the functionality you are targeting.
    We are continually improving our Linq support and we will have that issue in mind. Please find your Telerik points updated for bringing that to our attention.

    Best wishes,
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top