Skip to content

Commit 3f69817

Browse files
committed
Fix issues with the compiled model
Fixes #31727 Fixes #31720 Also fixed a formatting issue introduced in #31709 Added tests for all common types on SQLite and SQL Server.
1 parent 018ad06 commit 3f69817

File tree

9 files changed

+34332
-18061
lines changed

9 files changed

+34332
-18061
lines changed

src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,13 @@ protected override Expression VisitMethodCall(MethodCallExpression call)
14171417
methodIdentifier),
14181418
ArgumentList(SeparatedList(arguments[1..])));
14191419
}
1420+
else if (call.Method is { Name: "op_Equality", IsHideBySig: true, IsSpecialName: true })
1421+
{
1422+
Result = BinaryExpression(
1423+
SyntaxKind.EqualsExpression,
1424+
Translate<ExpressionSyntax>(call.Arguments[0]),
1425+
Translate<ExpressionSyntax>(call.Arguments[1]));
1426+
}
14201427
else
14211428
{
14221429
ExpressionSyntax expression;
@@ -1440,12 +1447,23 @@ ExpressionSyntax GetMemberAccessesForAllDeclaringTypes(Type type)
14401447
expression = Translate<ExpressionSyntax>(call.Object);
14411448
}
14421449

1443-
Result = InvocationExpression(
1444-
MemberAccessExpression(
1445-
SyntaxKind.SimpleMemberAccessExpression,
1450+
if (call.Method.Name.StartsWith("get_", StringComparison.Ordinal)
1451+
&& call.Method.GetParameters().Length == 1
1452+
&& call.Method is { IsHideBySig: true, IsSpecialName: true })
1453+
{
1454+
Result = ElementAccessExpression(
14461455
expression,
1447-
methodIdentifier),
1448-
ArgumentList(SeparatedList(arguments)));
1456+
BracketedArgumentList(SeparatedList(arguments)));
1457+
}
1458+
else
1459+
{
1460+
Result = InvocationExpression(
1461+
MemberAccessExpression(
1462+
SyntaxKind.SimpleMemberAccessExpression,
1463+
expression,
1464+
methodIdentifier),
1465+
ArgumentList(SeparatedList(arguments)));
1466+
}
14491467
}
14501468

14511469
if (call.Method.DeclaringType.Namespace is { } ns)
@@ -1904,7 +1922,11 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression node)
19041922
/// <inheritdoc />
19051923
protected override Expression VisitUnary(UnaryExpression unary)
19061924
{
1907-
if (unary.Method is not null)
1925+
if (unary.Method is not null
1926+
&& !unary.Method.IsHideBySig
1927+
&& !unary.Method.IsSpecialName
1928+
&& unary.Method.Name != "op_Implicit"
1929+
&& unary.Method.Name != "op_Explicit")
19081930
{
19091931
throw new NotImplementedException("Unary node with non-null method");
19101932
}

src/EFCore.Relational/Storage/ByteTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ByteTypeMapping : RelationalTypeMapping
2727
/// any release. You should only use it directly in your code with extreme caution and knowing that
2828
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2929
/// </summary>
30-
public static ByteArrayTypeMapping Default { get; } = new("tinyint");
30+
public static ByteTypeMapping Default { get; } = new("tinyint");
3131

3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="ByteTypeMapping" /> class.

src/EFCore.Sqlite.Core/Storage/Internal/SqliteGuidTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SqliteGuidTypeMapping : GuidTypeMapping
2020
/// any release. You should only use it directly in your code with extreme caution and knowing that
2121
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2222
/// </summary>
23-
public static new readonly SqliteGuidTypeMapping Default = new(SqliteTypeMappingSource.TextTypeName);
23+
public static new SqliteGuidTypeMapping Default { get; } = new(SqliteTypeMappingSource.TextTypeName);
2424

2525
/// <summary>
2626
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to

src/EFCore.Sqlite.Core/Storage/Internal/SqliteJsonTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static readonly ConstructorInfo MemoryStreamConstructor
3232
/// any release. You should only use it directly in your code with extreme caution and knowing that
3333
/// doing so can result in application failures when updating to a new Entity Framework Core release.
3434
/// </summary>
35-
public static readonly SqliteJsonTypeMapping Default = new(SqliteTypeMappingSource.TextTypeName);
35+
public static SqliteJsonTypeMapping Default { get; } = new(SqliteTypeMappingSource.TextTypeName);
3636

3737
/// <summary>
3838
/// Initializes a new instance of the <see cref="SqliteJsonTypeMapping" /> class.

src/EFCore.Sqlite.Core/Storage/Internal/SqliteStringTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class SqliteStringTypeMapping : StringTypeMapping
2121
/// any release. You should only use it directly in your code with extreme caution and knowing that
2222
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2323
/// </summary>
24-
public static new readonly SqliteStringTypeMapping Default = new(SqliteTypeMappingSource.TextTypeName);
24+
public static new SqliteStringTypeMapping Default { get; } = new(SqliteTypeMappingSource.TextTypeName);
2525

2626
/// <summary>
2727
/// Initializes a new instance of the <see cref="SqliteStringTypeMapping" /> class.

src/EFCore.Sqlite.Core/Storage/Internal/SqliteTimeOnlyTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SqliteTimeOnlyTypeMapping : TimeOnlyTypeMapping
2020
/// any release. You should only use it directly in your code with extreme caution and knowing that
2121
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2222
/// </summary>
23-
public static new readonly SqliteTimeOnlyTypeMapping Default = new(SqliteTypeMappingSource.TextTypeName);
23+
public static new SqliteTimeOnlyTypeMapping Default { get; } = new(SqliteTypeMappingSource.TextTypeName);
2424

2525
/// <summary>
2626
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to

src/EFCore.Sqlite.Core/Storage/Internal/SqliteULongTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SqliteULongTypeMapping : ULongTypeMapping
1919
/// any release. You should only use it directly in your code with extreme caution and knowing that
2020
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2121
/// </summary>
22-
public static new readonly SqliteULongTypeMapping Default = new(SqliteTypeMappingSource.IntegerTypeName);
22+
public static new SqliteULongTypeMapping Default { get; } = new(SqliteTypeMappingSource.IntegerTypeName);
2323

2424
/// <summary>
2525
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to

src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ public static void Create(
392392
CreateJsonValueReaderWriter((JsonValueReaderWriter)jsonReaderWriterProperty.GetValue(converter)!, parameters, codeHelper);
393393

394394
mainBuilder
395-
.Append(")")
396-
.DecrementIndent();
395+
.Append(")");
397396
}
398397
}
399398

@@ -443,8 +442,7 @@ public static void Create(
443442
Create((ValueComparer)elementComparerProperty.GetValue(comparer)!, parameters, codeHelper);
444443

445444
mainBuilder
446-
.Append(")")
447-
.DecrementIndent();
445+
.Append(")");
448446
}
449447
}
450448

0 commit comments

Comments
 (0)