Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public static TranslatedExpression Translate(TranslationContext context, Express

public static TranslatedExpression TranslateWithoutUnwrapping(TranslationContext context, Expression expression)
{
if (!context.HasResultSerializer(expression))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not validate it here, because serializer could be missing for different reasons here (it could be either not supported combination of parameters for known-expression, non-translatable expression, or simply not implemented yet expression).

{
throw new ExpressionNotSupportedException(expression, because: "we were unable to determine which serializer to use for the result");
}

switch (expression.NodeType)
{
case ExpressionType.Convert:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ internal static class ExpressionToFilterTranslator
// public methods
public static AstFilter Translate(TranslationContext context, Expression expression, bool exprOk = true)
{
if (!context.HasResultSerializer(expression))
{
throw new ExpressionNotSupportedException(expression, because: "we were unable to determine which serializer to use for the result");
}

AstFilter filter;
try
{
if (!context.HasResultSerializer(expression))
{
throw new ExpressionNotSupportedException(expression);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not really matter what we throws here as we will try fallback to expression language on line 45.

}

filter = TranslateUsingQueryOperators(context, expression);
}
catch (ExpressionNotSupportedException)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using MongoDB.Driver.Linq;
using MongoDB.Driver.TestHelpers;
using Xunit;

namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira;

public class CSharp5928Tests : LinqIntegrationTest<CSharp5928Tests.ClassFixture>
{
public CSharp5928Tests(ClassFixture fixture)
: base(fixture)
{
}

[Fact]
public void Non_translatable_expression_should_throw_expected_error()
{
var collection = Fixture.Collection;

var queryable = collection.AsQueryable()
.Where(c => c.CustomerId.CompareTo("AROUT".Replace("OUT".ToUpper(), c.CustomerId)) > 0);

var exception = Record.Exception(() => queryable.ToList());

exception.Should().BeOfType<ExpressionNotSupportedException>().Subject
.Message.Should().Contain("\"AROUT\".Replace(\"OUT\", c.CustomerId).");
}

public class C
{
public int Id { get; set; }
public string CustomerId { get; set; }
}

public sealed class ClassFixture : MongoCollectionFixture<C>
{
protected override IEnumerable<C> InitialData => null;
}
}