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 @@ -522,10 +522,20 @@ bool TryProcessJson(Expression expression, [NotNullWhen(true)] out SqlExpression
}
}

private bool TryTranslatePropertyAccess(Expression target, IPropertyBase property, [NotNullWhen(true)] out SqlExpression? translation)
private bool TryTranslatePropertyAccess(Expression target, IProperty property, [NotNullWhen(true)] out SqlExpression? translation)
{
var expression = CreatePropertyAccessExpression(target, property);
translation = Translate(expression);

if (property.GetTypeMapping() is RelationalTypeMapping relationalTypeMapping)
{
translation = Translate(expression, applyDefaultTypeMapping: false);
translation = _sqlExpressionFactory.ApplyTypeMapping(translation, relationalTypeMapping);
}
else
{
translation = Translate(expression);
}

return translation is not null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations.Schema;

namespace Microsoft.EntityFrameworkCore.Query;

// ReSharper disable ClassNeverInstantiated.Local
Expand Down Expand Up @@ -175,6 +177,49 @@ public class AllOptionalsComplexType

#endregion ShadowDiscriminator

#region 36837

[ConditionalFact]
public virtual async Task Complex_type_equality_with_non_default_type_mapping()
{
var contextFactory = await InitializeAsync<Context36837>(
seed: context =>
{
context.AddRange(
new Context36837.EntityType
{
ComplexThing = new Context36837.ComplexThing { DateTime = new DateTime(2020, 1, 1) }
});
return context.SaveChangesAsync();
});

await using var context = contextFactory.CreateContext();

var count = await context.Set<Context36837.EntityType>()
.CountAsync(b => b.ComplexThing == new Context36837.ComplexThing { DateTime = new DateTime(2020, 1, 1, 1, 1, 1, 999, 999) });
Assert.Equal(0, count);
}

private class Context36837(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<EntityType>().ComplexProperty(b => b.ComplexThing);

public class EntityType
{
public int Id { get; set; }
public ComplexThing ComplexThing { get; set; } = null!;
}

public class ComplexThing
{
[Column(TypeName = "datetime")] // Non-default type mapping
public DateTime DateTime { get; set; }
}
}

#endregion 36837

protected override string StoreName
=> "AdHocComplexTypeQueryTest";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ FROM [EntityType] AS [e]
""");
}

public override async Task Complex_type_equality_with_non_default_type_mapping()
{
await base.Complex_type_equality_with_non_default_type_mapping();

AssertSql(
"""
SELECT COUNT(*)
FROM [EntityType] AS [e]
WHERE [e].[ComplexThing_DateTime] = '2020-01-01T01:01:01.999'
""");
}

protected TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;

Expand Down
Loading