Skip to content

Commit

Permalink
Static analysis: use null propagation
Browse files Browse the repository at this point in the history
Part of #26805
  • Loading branch information
ajcvickers committed Dec 7, 2021
1 parent ad1cf49 commit cf288c2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,7 @@ private static void IncludeCollection<TIncludingEntity, TIncludedEntity>(
foreach (var relatedEntity in relatedEntities)
{
fixup(includingEntity, relatedEntity);
if (inverseNavigation != null)
{
inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
}
inverseNavigation?.SetIsLoadedWhenNoTracking(relatedEntity);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ private static void IncludeCollection<TEntity, TIncludingEntity, TIncludedEntity
if (!trackingQuery)
{
fixup(includingEntity, relatedEntity);
if (inverseNavigation != null)
{
inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
}
inverseNavigation?.SetIsLoadedWhenNoTracking(relatedEntity);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,7 @@ static RelationalDataReader InitializeReader(
if (!trackingQuery)
{
fixup(entity, relatedEntity);
if (inverseNavigation != null)
{
inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
}
inverseNavigation?.SetIsLoadedWhenNoTracking(relatedEntity);
}
}

Expand Down Expand Up @@ -1519,10 +1516,7 @@ static async Task<RelationalDataReader> InitializeReaderAsync(
if (!trackingQuery)
{
fixup(entity, relatedEntity);
if (inverseNavigation != null)
{
inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
}
inverseNavigation?.SetIsLoadedWhenNoTracking(relatedEntity);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ public virtual void ProcessEntityTypeAnnotationChanged(
typeof(DateTime),
periodPropertyName);

if (periodPropertyBuilder != null)
{
// set column name explicitly so that we don't try to uniquefy it to some other column
// in case another property is defined that maps to the same column
periodPropertyBuilder.HasColumnName(periodPropertyName);
}
// set column name explicitly so that we don't try to uniquefy it to some other column
// in case another property is defined that maps to the same column
periodPropertyBuilder?.HasColumnName(periodPropertyName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ public override void ProcessEntityTypeAnnotationChanged(
&& annotation?.Value is string propertyName)
{
var periodProperty = entityTypeBuilder.Metadata.FindProperty(propertyName);
if (periodProperty != null)
{
periodProperty.Builder.ValueGenerated(GetValueGenerated(periodProperty));
}
periodProperty?.Builder.ValueGenerated(GetValueGenerated(periodProperty));

// cleanup the previous period property - its possible that it won't be deleted
// (e.g. when removing period with default name, while the property with that same name has been explicitly defined)
if (oldAnnotation?.Value is string oldPropertyName)
{
var oldPeriodProperty = entityTypeBuilder.Metadata.FindProperty(oldPropertyName);
if (oldPeriodProperty != null)
{
oldPeriodProperty.Builder.ValueGenerated(GetValueGenerated(oldPeriodProperty));
}
oldPeriodProperty?.Builder.ValueGenerated(GetValueGenerated(oldPeriodProperty));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,9 @@ private static bool TryRemoveIfAmbiguous(

var existingAmbiguousNavigation = FindActualEntityType(ambiguousInverse.Value.Item2)!
.FindSkipNavigation(ambiguousInverse.Value.Item1);
if (existingAmbiguousNavigation != null)
{
existingAmbiguousNavigation.DeclaringEntityType.Builder.HasNoSkipNavigation(
existingAmbiguousNavigation, fromDataAnnotation: true);
}

existingAmbiguousNavigation?.DeclaringEntityType.Builder.HasNoSkipNavigation(
existingAmbiguousNavigation, fromDataAnnotation: true);

remainingInverseNavigation = entityType.FindSkipNavigation(navigationMemberInfo)?.ForeignKey!.Builder;
return true;
Expand Down
10 changes: 2 additions & 8 deletions src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ public virtual bool CanSetForeignKey(ForeignKey? foreignKey, ConfigurationSource
return null;
}

if (inverse != null)
{
inverse.UpdateConfigurationSource(configurationSource);
}
inverse?.UpdateConfigurationSource(configurationSource);

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

Expand All @@ -156,10 +153,7 @@ public virtual bool CanSetForeignKey(ForeignKey? foreignKey, ConfigurationSource

Metadata.SetInverse(inverse, configurationSource);

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

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,7 @@ private Expression ExpandForeignKey(
&& entityReference.IncludePaths.TryGetValue(navigation, out var pendingIncludeTree))
{
var cachedEntityReference = UnwrapEntityReference(expansion);
if (cachedEntityReference != null)
{
cachedEntityReference.IncludePaths.Merge(pendingIncludeTree);
}
cachedEntityReference?.IncludePaths.Merge(pendingIncludeTree);
}

return expansion;
Expand Down

0 comments on commit cf288c2

Please sign in to comment.