1

Closed

Add cast in select projection.

description

Please add cast support in select projection.
Now query:

context.Query<User>().Select(p => ((User)p).DisplayName).ToList();

throw not support exception. This syntax used by Odata Web Api.


PS. I fixed it using

m.Expression != null && (m.Expression.NodeType == ExpressionType.Parameter || m.Expression.NodeType == ExpressionType.TypeAs)

condition in SelectProjector.VisitMemberAccess.
Closed Sep 8, 2015 at 1:36 AM by MadHatter22
Released

comments

MadHatter22 wrote Aug 30, 2015 at 2:54 AM

Thanks for the test case and solution!

wrote Aug 30, 2015 at 2:54 AM

ilchert wrote Aug 30, 2015 at 7:52 AM

Correction:
Odata use following cast:

context.Query<User>().Select(p => (p as User).DisplayName).ToList();

And to fix both issues, condition should be expanded to

if (m.Expression != null && (m.Expression.NodeType == ExpressionType.Parameter || m.Expression.NodeType == ExpressionType.TypeAs || m.Expression.NodeType==ExpressionType.Convert))

wrote Aug 31, 2015 at 12:04 AM

Associated with changeset 40241: Added cast support within projections.
Updated tests to account for using GetMapping(type) instead of GetMapping().

wrote Aug 31, 2015 at 12:05 AM

wrote Sep 8, 2015 at 1:36 AM