Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the TryGetValue method #21817

Merged
merged 1 commit into from
Jul 28, 2020
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
4 changes: 2 additions & 2 deletions src/EFCore.Design/Scaffolding/Internal/CSharpNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public virtual string GetName([NotNull] T item)
{
Check.NotNull(item, nameof(item));

if (NameCache.ContainsKey(item))
if (NameCache.TryGetValue(item, out var cachedName))
{
return NameCache[item];
return cachedName;
}

var name = _cSharpUtilities.GenerateCSharpIdentifier(
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ public virtual void Delete(IUpdateEntry entry)
{
var key = CreateKey(entry);

if (_rows.ContainsKey(key))
if (_rows.TryGetValue(key, out var row))
{
var properties = entry.EntityType.GetProperties().ToList();
var concurrencyConflicts = new Dictionary<IProperty, object>();

for (var index = 0; index < properties.Count; index++)
{
IsConcurrencyConflict(entry, properties[index], _rows[key][index], concurrencyConflicts);
IsConcurrencyConflict(entry, properties[index], row[index], concurrencyConflicts);
}

if (concurrencyConflicts.Count > 0)
Expand Down Expand Up @@ -255,7 +255,7 @@ public virtual void Update(IUpdateEntry entry)
{
var key = CreateKey(entry);

if (_rows.ContainsKey(key))
if (_rows.TryGetValue(key, out var row))
{
var properties = entry.EntityType.GetProperties().ToList();
var comparers = GetKeyComparers(properties);
Expand All @@ -264,14 +264,14 @@ public virtual void Update(IUpdateEntry entry)

for (var index = 0; index < valueBuffer.Length; index++)
{
if (IsConcurrencyConflict(entry, properties[index], _rows[key][index], concurrencyConflicts))
if (IsConcurrencyConflict(entry, properties[index], row[index], concurrencyConflicts))
{
continue;
}

valueBuffer[index] = entry.IsModified(properties[index])
? SnapshotValue(properties[index], comparers[index], entry)
: _rows[key][index];
: row[index];
}

if (concurrencyConflicts.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public virtual void ProcessEntityTypeBaseTypeChanged(
else if (oldBaseType != null
&& newBaseType == null
&& entityType.ClrType != null
&& _sets.ContainsKey(entityType.ClrType))
&& _sets.TryGetValue(entityType.ClrType, out var setName))
{
entityTypeBuilder.ToTable(_sets[entityType.ClrType]);
entityTypeBuilder.ToTable(setName);
}
}

Expand All @@ -100,9 +100,9 @@ public virtual void ProcessEntityTypeAdded(
var entityType = entityTypeBuilder.Metadata;
if (entityType.BaseType == null
&& entityType.ClrType != null
&& _sets.ContainsKey(entityType.ClrType))
&& _sets.TryGetValue(entityType.ClrType, out var setName))
{
entityTypeBuilder.ToTable(_sets[entityType.ClrType]);
entityTypeBuilder.ToTable(setName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ FROM [sys].[sequences] AS [s]
MaxValue = maxValue
};

if (_defaultSequenceMinMax.ContainsKey(storeType))
if (_defaultSequenceMinMax.TryGetValue(storeType, out var defaultMinMax))
{
var defaultMin = _defaultSequenceMinMax[storeType][0];
var defaultMin = defaultMinMax[0];
sequence.MinValue = sequence.MinValue == defaultMin ? null : sequence.MinValue;
sequence.StartValue = sequence.StartValue == defaultMin ? null : sequence.StartValue;

sequence.MaxValue = sequence.MaxValue == _defaultSequenceMinMax[sequence.StoreType][1]
sequence.MaxValue = sequence.MaxValue == defaultMinMax[1]
? null
: sequence.MaxValue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore/Query/ExpressionPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,8 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres
{
Check.NotNull(parameterExpression, nameof(parameterExpression));

if (_parametersInScope.ContainsKey(parameterExpression))
if (_parametersInScope.TryGetValue(parameterExpression, out var parameterName))
{
var parameterName = _parametersInScope[parameterExpression];
if (parameterName == null)
{
if (!_namelessParameters.Contains(parameterExpression))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ protected Expression ExpandNavigation(

var ownedEntityReference = new EntityReference(targetType);
ownedEntityReference.MarkAsOptional();
if (entityReference.IncludePaths.ContainsKey(navigation))
if (entityReference.IncludePaths.TryGetValue(navigation, out var includePath))
{
ownedEntityReference.IncludePaths.Merge(entityReference.IncludePaths[navigation]);
ownedEntityReference.IncludePaths.Merge(includePath);
}

ownedExpansion = new OwnedNavigationReference(root, navigation, ownedEntityReference);
Expand Down