Skip to content

Conversation

AndriySvyryd
Copy link
Member

No description provided.

@AndriySvyryd AndriySvyryd requested a review from a team as a code owner August 13, 2025 03:33
@roji
Copy link
Member

roji commented Aug 13, 2025

What's the relationship between this and #36562?

@SamMonoRT SamMonoRT requested a review from Copilot August 13, 2025 11:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR contains code cleanup for the src directory, modernizing C# syntax patterns to improve code readability and conciseness. The changes primarily involve adopting newer C# features such as collection expressions, target-typed patterns, and simplified syntax constructs.

  • Replacement of array initialization syntax with collection expressions (new[] { ... }[...])
  • Modernization of pattern matching using target-typed patterns (is Type variableis { } variable)
  • Simplification of empty collection initialization (Enumerable.Empty<T>()[])

Reviewed Changes

Copilot reviewed 292 out of 350 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Multiple convention files Updated pattern matching and array initialization syntax in metadata conventions
Query translator files Modernized array initialization in SQL Server and SQLite query translators
Storage and update files Simplified collection patterns in relational storage and update components
Extension files Updated service collection and extension method syntax patterns
Design files Modernized code generation and annotation handling patterns
Comments suppressed due to low confidence (5)

src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs:1450

  • [nitpick] Empty line addition appears unnecessary and adds visual clutter to the code.
                            }

@@ -80,7 +80,7 @@ public static void SetContainer(this IMutableEntityType entityType, string? name
}

private static string? GetDefaultContainingPropertyName(IReadOnlyEntityType entityType)
=> entityType.FindOwnership() is IReadOnlyForeignKey ownership
=> entityType.FindOwnership() is { } ownership
Copy link
Member

Choose a reason for hiding this comment

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

Ok with the change, but doesn't having an explicit type help with readability and debugging? Applies to here and other places.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks strange at first, but as you get used to it it's actually more readable as you immediately know that it's just a null check and it's not trying to cast to a different type.

Copy link
Member

Choose a reason for hiding this comment

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

As in the other PR, I'm slightly on the fence (can see both sides). On the one hand clearly making something as a null check is valuable (as @AndriySvyryd says), on the other hand simply having the .NET type explicitly is also valuable in at least some situations. It's a bit like how sometimes it's better to avoid var in order to make it very clear what type is being used.

But am OK with it either way.

? lastPropertyNameSegment.PropertyName!
: GenerateTableAlias(jsonScalar.Json),
=> jsonScalar.Path.LastOrDefault(s => s.PropertyName is not null).PropertyName
?? GenerateTableAlias(jsonScalar.Json),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a bug fix. PathSegment is a value type, so LastOrDefault never returned null

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. Can also do jsonScalar.Path.Select(s => s.PropertyName).LastOrDefault() ?? ... to simplify silghtly.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

LGTM. Checked comments, did not go over all the code cleanup changes (did that in the previosu PR).

? lastPropertyNameSegment.PropertyName!
: GenerateTableAlias(jsonScalar.Json),
=> jsonScalar.Path.LastOrDefault(s => s.PropertyName is not null).PropertyName
?? GenerateTableAlias(jsonScalar.Json),
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. Can also do jsonScalar.Path.Select(s => s.PropertyName).LastOrDefault() ?? ... to simplify silghtly.

@@ -80,7 +80,7 @@ public static void SetContainer(this IMutableEntityType entityType, string? name
}

private static string? GetDefaultContainingPropertyName(IReadOnlyEntityType entityType)
=> entityType.FindOwnership() is IReadOnlyForeignKey ownership
=> entityType.FindOwnership() is { } ownership
Copy link
Member

Choose a reason for hiding this comment

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

As in the other PR, I'm slightly on the fence (can see both sides). On the one hand clearly making something as a null check is valuable (as @AndriySvyryd says), on the other hand simply having the .NET type explicitly is also valuable in at least some situations. It's a bit like how sometimes it's better to avoid var in order to make it very clear what type is being used.

But am OK with it either way.

@@ -57,7 +57,11 @@ protected override Expression VisitExtension(Expression expression)

// Converts Offset and Limit parameters to constants when ORDER BY RANK is detected in the SelectExpression (i.e. we order by scoring function)
// Cosmos only supports constants in Offset and Limit for this scenario currently (ORDER BY RANK limitation)
case SelectExpression { Orderings: [{ Expression: SqlFunctionExpression { IsScoringFunction: true } }], Limit: var limit, Offset: var offset } hybridSearch
case SelectExpression
{
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be unindented? Feels like there are some bugs around this in the cleanup (but not blocking).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is correct as this block is part of the case condition.

@AndriySvyryd AndriySvyryd merged commit 118bb72 into main Aug 14, 2025
7 checks passed
@AndriySvyryd AndriySvyryd deleted the SourceCleanup branch August 14, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants