This is a migrated thread and some comments may be shown as answers.

Linq Expression problem

1 Answer 56 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
steve
Top achievements
Rank 1
steve asked on 26 Feb 2011, 10:16 AM
Hi,

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));

to
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

Regards

Steve Hayles

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 10 Mar 2011, 07:43 PM
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,
Petar
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!
Tags
LINQ (LINQ specific questions)
Asked by
steve
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or