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

UseAsDataSource doesn't support expand and select in OData projections #1953

Closed
pculver opened this issue Feb 13, 2017 · 9 comments
Closed

Comments

@pculver
Copy link

pculver commented Feb 13, 2017

I suspect this is a feature request.

The Automapper OData samples have the tests for select and expand marked as Not supported yet. Is there a plan to expand Automapper to support expand and select when using the UseAsDataSource functionality? Note in my testing, the expand functionality works correctly when using ProjectTo.

Any recommendations to work around this. I would be happy to use ProjectTo but I need the functionality of OnEnumeration and BeforeProjection in my code.

Both my project and the sample code throw a ArgumentException when attempting to use expand that state Argument types do not match.

@TylerCarlson1
Copy link
Member

Can you try the MyGet build and see if this works.

@jbogard #1923 or #1916 might fix this issue with the improved expression translation.

@pculver
Copy link
Author

pculver commented Feb 14, 2017

I tried the MyGet build (5.3.0-alpha-01286) and it still fails with UseAsDataSource.

Exception details:

{"odata.error": {
   "code": "",
   "message":    {
      "lang": "en-US",
      "value": "An error has occurred."
   },
   "innererror":    {
      "message": "Argument types do not match",
      "type": "System.ArgumentException",
      "stacktrace": "   at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression)\r\n   at System.Linq.Expressions.MemberAssignment.Update(Expression expression)\r\n   at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment node)\r\n   at System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit[T](ReadOnlyCollection`1 nodes, Func`2 elementVisitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.VisitMemberInit(MemberInitExpression node)\r\n   at System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambdaExpression[T](Expression`1 expression)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambda[T](Expression`1 expression)\r\n   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.<>c__23`1.<VisitAllParametersExpression>b__23_1(Expression e, ExpressionVisitor v)\r\n   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitAllParametersExpression[T](Expression`1 expression)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambda[T](Expression`1 expression)\r\n   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)\r\n   at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)\r\n   at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.GetConvertedMethodCall(MethodCallExpression node)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitMethodCall(MethodCallExpression node)\r\n   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)\r\n   at AutoMapper.QueryableExtensions.Impl.SourceInjectedQueryProvider`2.ConvertDestinationExpressionToSourceExpression(Expression expression)\r\n   at AutoMapper.QueryableExtensions.Impl.SourceInjectedQueryProvider`2.Execute[TResult](Expression expression)\r\n   at AutoMapper.QueryableExtensions.Impl.SourceSourceInjectedQuery`2.GetEnumerator()\r\n   at AutoMapper.QueryableExtensions.Impl.SourceSourceInjectedQuery`2.System.Collections.IEnumerable.GetEnumerator()\r\n   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n   at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n   at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__13.MoveNext()"
   }
}}

@lbargaoanu
Copy link
Member

@pculver MyGet is built from master. Those PR-s are not merged into master yet. The code is in the PR's branch.

@jbogard
Copy link
Member

jbogard commented Feb 16, 2017

@TylerCarlson1 so I'm still inclined to pull in #1923.

@jbogard
Copy link
Member

jbogard commented Feb 16, 2017

sorry, meant #1916

@lbargaoanu
Copy link
Member

Try the MyGet build.

@pculver
Copy link
Author

pculver commented Mar 3, 2017

This still fails in MyGet (5.3.0-alpha-01291) as well as the unit test in master. For example in ODataQueryTests.cs remove the Ignore attribute from the SupportsExpand unit test and run the test.

It will fail as follows:

Test Name: SupportsExpand
Test FullName: AutoMapperSamples.OData.ODataQueryTests.SupportsExpand
Test Source: D:\SOURCE\Other\Automapper\src\AutoMapperSamples.OData\ODataQueryTests.cs : line 377
Test Outcome: Failed
Test Duration: 0:00:01.356

Result StackTrace: at AutoMapperSamples.OData.ODataQueryTests.SupportsExpand() in D:\SOURCE\Other\Automapper\src\AutoMapperSamples.OData\ODataQueryTests.cs:line 389
Result Message:
Argument types do not match
at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression)
at System.Linq.Expressions.MemberAssignment.Update(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment node)
at System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)
at System.Linq.Expressions.ExpressionVisitor.Visit[T](ReadOnlyCollection1 nodes, Func2 elementVisitor)
at System.Linq.Expressions.ExpressionVisitor.VisitMemberInit(MemberInitExpression node)
at System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambdaExpression[T](Expression1 expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 198 at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambda[T](Expression1 expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 192
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.<>c__231.b__23_1(Expression e, ExpressionVisitor v) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 222
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func)
at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitAllParametersExpression[T](Expression1 expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 222 at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitLambda[T](Expression1 expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 193
at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes)
at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.GetConvertedMethodCall(MethodCallExpression node) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 95
at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitMethodCall(MethodCallExpression node) in D:\SOURCE\Other\Automapper\src\AutoMapper\Mappers\ExpressionMapper.cs:line 81
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at AutoMapper.QueryableExtensions.Impl.SourceInjectedQueryProvider2.ConvertDestinationExpressionToSourceExpression(Expression expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\QueryableExtensions\Impl\SourceInjectedQueryProvider.cs:line 280 at AutoMapper.QueryableExtensions.Impl.SourceInjectedQueryProvider2.Execute[TResult](Expression expression) in D:\SOURCE\Other\Automapper\src\AutoMapper\QueryableExtensions\Impl\SourceInjectedQueryProvider.cs:line 225
at AutoMapper.QueryableExtensions.Impl.SourceSourceInjectedQuery2.GetEnumerator() in D:\SOURCE\Other\Automapper\src\AutoMapper\QueryableExtensions\Impl\SourceInjectedQuery.cs:line 73 at AutoMapper.QueryableExtensions.Impl.SourceSourceInjectedQuery2.System.Collections.IEnumerable.GetEnumerator() in D:\SOURCE\Other\Automapper\src\AutoMapper\QueryableExtensions\Impl\SourceInjectedQuery.cs:line 79
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)
at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Owin.HttpMessageHandlerAdapter.d__13.MoveNext()

@lbargaoanu
Copy link
Member

PR welcome.

@lock
Copy link

lock bot commented May 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants