Skip to content

Commit

Permalink
Tiny cleanup (#26904)
Browse files Browse the repository at this point in the history
After #26806
  • Loading branch information
roji authored Dec 6, 2021
1 parent 57d1ec9 commit c5612d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 52 deletions.
34 changes: 6 additions & 28 deletions src/EFCore/DbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,13 @@ public virtual DbContextOptionsBuilder LogTo(

var eventsArray = events.ToArray();

switch (eventsArray.Length)
return eventsArray.Length switch
{
case 0:
return this;
case 1:
{
var firstEvent = eventsArray[0];
return LogTo(
action,
(eventId, level) => level >= minimumLevel
&& eventId == firstEvent,
options);
}
case < 6:
return LogTo(
action,
(eventId, level) => level >= minimumLevel
&& eventsArray.Contains(eventId),
options);
default:
{
var eventsHash = eventsArray.ToHashSet();
return LogTo(
action,
(eventId, level) => level >= minimumLevel
&& eventsHash.Contains(eventId),
options);
}
}
0 => this,
1 => LogTo(action, (eventId, level) => level >= minimumLevel && eventId == eventsArray[0], options),
< 6 => LogTo(action, (eventId, level) => level >= minimumLevel && eventsArray.Contains(eventId), options),
_ => LogTo(action, (eventId, level) => level >= minimumLevel && eventsArray.ToHashSet().Contains(eventId), options)
};
}

/// <summary>
Expand Down
14 changes: 2 additions & 12 deletions src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,12 +1906,7 @@ private bool CanSetForeignKey(
Metadata.PrincipalEntityType.Builder.GetOrCreateProperties(members, configurationSource),
configurationSource);

if (relationship == null)
{
return null;
}

return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder;
return relationship is null ? null : (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder;
}

/// <summary>
Expand All @@ -1930,12 +1925,7 @@ private bool CanSetForeignKey(
Metadata.PrincipalEntityType.Builder.GetOrCreateProperties(propertyNames, configurationSource),
configurationSource);

if (relationship == null)
{
return null;
}

return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder;
return relationship is null ? null : (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder;
}

/// <summary>
Expand Down
21 changes: 10 additions & 11 deletions src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,19 @@ public virtual bool CanSetForeignKey(ForeignKey? foreignKey, ConfigurationSource
inverse.UpdateConfigurationSource(configurationSource);
}

using (Metadata.DeclaringEntityType.Model.DelayConventions())
using var _ = Metadata.DeclaringEntityType.Model.DelayConventions();

if (Metadata.Inverse != null
&& Metadata.Inverse != inverse)
{
if (Metadata.Inverse != null
&& Metadata.Inverse != inverse)
{
Metadata.Inverse.SetInverse(null, configurationSource);
}
Metadata.Inverse.SetInverse(null, configurationSource);
}

Metadata.SetInverse(inverse, configurationSource);
Metadata.SetInverse(inverse, configurationSource);

if (inverse != null)
{
inverse.SetInverse(Metadata, configurationSource);
}
if (inverse != null)
{
inverse.SetInverse(Metadata, configurationSource);
}

return this;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Query/ExpressionPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private string PrintCore(
&& characterLimit.Value > 0)
{
queryPlan = queryPlan.Length > characterLimit
? string.Concat(queryPlan.AsSpan(0, characterLimit.Value), "...")
? queryPlan[..characterLimit.Value] + "..."
: queryPlan;
}

Expand Down

0 comments on commit c5612d6

Please sign in to comment.