Skip to content

Case Insensitive string comparison in Composite Foreign Keys #27467

@Hylaean

Description

@Hylaean

I fond an issue in a model were navigability of entities didn't work when casing changed between the target and source tables.
When a case insensitive comparer is added, it seems the inner and outer key selectors can't be translated.

Exception:

   System.InvalidOperationException : The LINQ expression 'DbSet<Product>()
        .Where(p => p.SubscriptionId == __subscriptionId_0 || p.SubscriptionId == -1)
        .Where(p => p.ProductCode == __productCode_1 && !(p.IsDeleted))
        .Join(
            inner: DbSet<ProductDefinition>(), 
            outerKeySelector: p => new object[]
            { 
                (object)EF.Property<int?>(p, "SubscriptionId"), 
                (object)EF.Property<string>(p, "ProductCode"), 
                (object)EF.Property<string>(p, "CustomerCode") 
            }, 
            innerKeySelector: p0 => new object[]
            { 
                (object)EF.Property<int?>(p0, "SubscriptionId"), 
                (object)EF.Property<string>(p0, "ProductCode"), 
                (object)EF.Property<string>(p0, "CustomerCode") 
            }, 
            resultSelector: (o, i) => new TransparentIdentifier<Product, ProductDefinition>(
                Outer = o, 
                Inner = i
            ))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

  Stack Trace: 
    QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& )
    QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    InMemoryQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    MethodCallExpression.Accept(ExpressionVisitor visitor)
    ExpressionVisitor.Visit(Expression node)
    QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    InMemoryQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    MethodCallExpression.Accept(ExpressionVisitor visitor)
    ExpressionVisitor.Visit(Expression node)
    QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)

version information

EF Core version: 6.0.2
Database provider: *
Target framework: .NET 6.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions