Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1771

Support IIF method (i.e. ternary operator) in LINQ

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: 2.3
    • Component/s: Linq, LINQ3
    • Environment:
      win 10, .net 4.6.1

      I'm trying to use the new driver to support an OData webapi service.
      I have "tenants" collection, a "tenant" document includes "applications" collection.
      This query fails:
      http://dev.api.axonize.com/odata/tenants?$expand=applications
      With this stack trace:

      { "error":{ "code":"","message":"An error has occurred.","innererror":{ "message":"The expression tree is not supported: IIF(({document} == null), null, {document}{applications})","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.Owin.HttpMessageHandlerAdapter.d__13.MoveNext()" } } }

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            omricohen Omri Cohen
            Votes:
            11 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved: