Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NORM cannot handle lambda expressions where the type is an interface type #49

Open
IanMercer opened this issue Nov 14, 2010 · 0 comments

Comments

@IanMercer
Copy link

NORM cannot handle expressions where the type is an interface type.

For example, in a generic class that has an interface constraint on the type, when I access a property of T, e.g. ".UniqueIdentifier" NORM cannot handle the expression and an Exception is thrown (relating to its inability to case a UnaryExpression to a ParameterExpression).

            var existing = db.GetCollection<T>().AsQueryable().SingleOrDefault(x => x.UniqueIdentifier == uid);

In this expression 'x.UniqueIdentifier' has a NodeType=Convert wrapped around it to perform the cast to the interface.

It's actually a fairly simple fix: In MongoQueryTranslator.cs, about line 407 there is an if statement in ...

    private static ParameterExpression GetParameterExpression(Expression expression)

Adding the following clause to the if statement solves the problem:

    ...
            else if (parentExpression.NodeType == ExpressionType.Convert)
            {
                parentExpression = ((UnaryExpression)parentExpression).Operand;
                expressionRoot = parentExpression is ParameterExpression;
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant