[CSHARP-1554] OData get fails when using $expand Created: 03/Feb/16  Updated: 12/Dec/18  Resolved: 10/Dec/18

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Omri Cohen Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, Asp.Net OData web api



 Description   

When using OData and sending $expand option with linq on the new driver (IMongoCollection) it throws exception:
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal'.",
"type": "System.InvalidOperationException",
"stacktrace": "",
"internalexception": {
"message": "The expression tree is not supported: IIF((

{document} == null), null, {document} {groups}

)",
"type": "System.NotSupportedException",
"stacktrace": " at MongoDB.Driver.Linq.Processors.EmbeddedPipeline.EmbeddedPipelineBinder.BindNonMethodCall(Expression node)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindPipeline(Expression node)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)\r\n at MongoDB.Driver.Linq.Processors.EmbeddedPipeline.EmbeddedPipelineBinder.Bind(Expression node, IBindingContext parent)\r\n at MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)\r\n at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node)\r\n at MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)\r\n at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment 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 MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)\r\n at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment 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 MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)\r\n at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment 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 MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)\r\n at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.SelectBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)\r\n at MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder`1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)\r\n at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)\r\n at MongoDB.Driver.Linq.Processors.Pipeline.PipelineBinder.Bind(Expression node, IBsonSerializerRegistry serializerRegistry)\r\n at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Prepare(Expression expression)\r\n at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)\r\n at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)\r\n at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()\r\n at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n at System.Web.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.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()"
}
}
}



 Comments   
Comment by Ian Whalen (Inactive) [ 12/Dec/18 ]

omricohen Many apologies for the delay, we're just digging ourselves out of a big backlog now. We have no plans to work on OData support for the foreseeable future and so we'd prefer to just close this so as to communicate the real state of our roadmap.

Comment by Omri Cohen [ 11/Dec/18 ]

It took you almost 3 years to close it because you don't support OData?
Wouldn't it be easier to support OData?
I think it's a mistake to abandon this great protocol and would make companies to upgrade to CosmosDB.

Comment by Ian Whalen (Inactive) [ 10/Dec/18 ]

Closing as Won't Fix since we do not support OData.

Comment by Omri Cohen [ 06/Feb/16 ]

Sure, http://api.ourserver.com/odata/Devices?$expand=groups
Where groups is a navigation property on Device entity.

[DataMember(Name = "groups")]
public IList<GroupNode> Groups

{ get; set; }

Device entity in Mongo:
{
_id:value,
groups:[{_id:value, name:value},{_id:value, name:value}]
}

BTW, It works perfect with the old driver but I don't want one code path for selecting (old driver) and another code path for changing data (new driver)
Thanks!

Comment by Craig Wilson [ 03/Feb/16 ]

Hi Omri,

We haven't specifically supported OData. However, I'll add this into our undecided bucket for now. I'll also do a little investigation to see if this is something else entirely. Could you please provide the entire OData query string so I can see exactly what the expression going into the driver is?

Craig

Generated at Wed Feb 07 21:39:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.