diff --git a/EFCore.sln.DotSettings b/EFCore.sln.DotSettings
index b8b7f701254..0225629c00b 100644
--- a/EFCore.sln.DotSettings
+++ b/EFCore.sln.DotSettings
@@ -113,6 +113,7 @@
Required
Required
Required
+ Join
ExplicitlyTyped
True
False
diff --git a/src/EFCore.SqlServer.HierarchyId/EFCore.SqlServer.HierarchyId.csproj b/src/EFCore.SqlServer.HierarchyId/EFCore.SqlServer.HierarchyId.csproj
index 88797f4922e..24fc80cb15c 100644
--- a/src/EFCore.SqlServer.HierarchyId/EFCore.SqlServer.HierarchyId.csproj
+++ b/src/EFCore.SqlServer.HierarchyId/EFCore.SqlServer.HierarchyId.csproj
@@ -23,8 +23,9 @@
-
+
+
diff --git a/src/EFCore/ChangeTracking/CollectionEntry.cs b/src/EFCore/ChangeTracking/CollectionEntry.cs
index 648ce048907..859ff54a344 100644
--- a/src/EFCore/ChangeTracking/CollectionEntry.cs
+++ b/src/EFCore/ChangeTracking/CollectionEntry.cs
@@ -25,8 +25,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
///
public class CollectionEntry : NavigationEntry
{
- private ICollectionLoader? _loader;
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -164,11 +162,12 @@ public override bool IsModified
{
var joinEntityType = skipNavigation.JoinEntityType;
var foreignKey = skipNavigation.ForeignKey;
- foreach (var joinEntry in stateManager
- .GetEntriesForState(added: !value, modified: !value, deleted: !value, unchanged: value).Where(
- e => e.EntityType == joinEntityType
- && stateManager.FindPrincipal(e, foreignKey) == InternalEntry)
- .ToList())
+ var joinEntries = stateManager
+ .GetEntriesForState(added: !value, modified: !value, deleted: !value, unchanged: value)
+ .Where(e => e.EntityType == joinEntityType
+ && stateManager.FindPrincipal(e, foreignKey) == InternalEntry)
+ .ToList();
+ foreach (var joinEntry in joinEntries)
{
joinEntry.SetEntityState(value ? EntityState.Modified : EntityState.Unchanged);
}
@@ -335,8 +334,9 @@ private void EnsureInitialized()
? null
: InternalEntry.StateManager.GetOrCreateEntry(entity, Metadata.TargetEntityType);
+ [field: AllowNull, MaybeNull]
private ICollectionLoader TargetLoader
- => _loader ??= Metadata is IRuntimeSkipNavigation skipNavigation
+ => field ??= Metadata is IRuntimeSkipNavigation skipNavigation
? skipNavigation.GetManyToManyLoader()
: new EntityFinderCollectionLoaderAdapter(
InternalEntry.StateManager.CreateEntityFinder(Metadata.TargetEntityType),
diff --git a/src/EFCore/ChangeTracking/ComplexCollectionEntry.cs b/src/EFCore/ChangeTracking/ComplexCollectionEntry.cs
index 2cdb30888d6..3f21861c3d8 100644
--- a/src/EFCore/ChangeTracking/ComplexCollectionEntry.cs
+++ b/src/EFCore/ChangeTracking/ComplexCollectionEntry.cs
@@ -79,18 +79,18 @@ private void DetectChanges()
}
///
- /// Gets a for the complex item at the specified ordinal.
+ /// Gets a for the complex item at the specified ordinal.
///
/// The ordinal of the complex item to access.
- /// A for the complex item at the specified ordinal.
+ /// A for the complex item at the specified ordinal.
public virtual ComplexElementEntry this[int ordinal]
=> new(InternalEntry.GetComplexCollectionEntry(Metadata, ordinal));
///
- /// Gets a for the original complex item at the specified ordinal.
+ /// Gets a for the original complex item at the specified ordinal.
///
/// The original ordinal of the complex item to access.
- /// A for the complex item at the specified original ordinal.
+ /// A for the complex item at the specified original ordinal.
public virtual ComplexElementEntry GetOriginalEntry(int ordinal)
=> new(InternalEntry.GetComplexCollectionOriginalEntry(Metadata, ordinal));
diff --git a/src/EFCore/ChangeTracking/ComplexCollectionEntry`.cs b/src/EFCore/ChangeTracking/ComplexCollectionEntry`.cs
index 9ee84858943..29ee014f627 100644
--- a/src/EFCore/ChangeTracking/ComplexCollectionEntry`.cs
+++ b/src/EFCore/ChangeTracking/ComplexCollectionEntry`.cs
@@ -66,18 +66,18 @@ public override EntityEntry EntityEntry
}
///
- /// Gets a for the complex item at the specified ordinal.
+ /// Gets a for the complex item at the specified ordinal.
///
/// The ordinal of the complex item to access.
- /// A for the complex item at the specified ordinal.
+ /// A for the complex item at the specified ordinal.
public override ComplexElementEntry this[int ordinal]
=> new(InternalEntry.GetComplexCollectionEntry(Metadata, ordinal));
///
- /// Gets a for the complex item at the specified original ordinal.
+ /// Gets a for the complex item at the specified original ordinal.
///
/// The original ordinal of the complex item to access.
- /// A for the original complex item at the specified ordinal.
+ /// A for the original complex item at the specified ordinal.
public override ComplexElementEntry GetOriginalEntry(int ordinal)
=> new(InternalEntry.GetComplexCollectionOriginalEntry(Metadata, ordinal));
}
diff --git a/src/EFCore/ChangeTracking/ComplexElementEntry.cs b/src/EFCore/ChangeTracking/ComplexElementEntry.cs
index 083f9eb52c4..b276a48bafb 100644
--- a/src/EFCore/ChangeTracking/ComplexElementEntry.cs
+++ b/src/EFCore/ChangeTracking/ComplexElementEntry.cs
@@ -33,9 +33,7 @@ public class ComplexElementEntry : IInfrastructure
///
[EntityFrameworkInternal]
public ComplexElementEntry(InternalComplexEntry internalEntry)
- {
- InternalEntry = internalEntry;
- }
+ => InternalEntry = internalEntry;
///
/// Gets or sets a value indicating whether any of the properties of the complex type have been modified
@@ -85,7 +83,8 @@ public virtual bool IsModified
///
/// Gets the metadata that describes the facets of this property and how it maps to the database.
///
- public virtual IComplexProperty Metadata => InternalEntry.ComplexProperty;
+ public virtual IComplexProperty Metadata
+ => InternalEntry.ComplexProperty;
///
/// Gets or sets the value currently assigned to this property. If the current value is set using this property,
@@ -273,7 +272,8 @@ public virtual ComplexCollectionEntry ComplexCollection(string propertyName)
/// examples.
///
public virtual IEnumerable ComplexCollections
- => Metadata.ComplexType.GetComplexProperties().Where(p => p.IsCollection).Select(property => new ComplexCollectionEntry(InternalEntry, property));
+ => Metadata.ComplexType.GetComplexProperties().Where(p => p.IsCollection)
+ .Select(property => new ComplexCollectionEntry(InternalEntry, property));
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore/ChangeTracking/ComplexPropertyEntry.cs b/src/EFCore/ChangeTracking/ComplexPropertyEntry.cs
index b1424b02427..02e6e317f35 100644
--- a/src/EFCore/ChangeTracking/ComplexPropertyEntry.cs
+++ b/src/EFCore/ChangeTracking/ComplexPropertyEntry.cs
@@ -166,7 +166,8 @@ public virtual ComplexPropertyEntry ComplexProperty(string propertyName)
/// examples.
///
public virtual IEnumerable ComplexProperties
- => Metadata.ComplexType.GetComplexProperties().Where(p => !p.IsCollection).Select(property => new ComplexPropertyEntry(InternalEntry, property));
+ => Metadata.ComplexType.GetComplexProperties().Where(p => !p.IsCollection)
+ .Select(property => new ComplexPropertyEntry(InternalEntry, property));
///
/// Provides access to change tracking information and operations for a given collection property of a complex type on this complex type.
@@ -208,5 +209,6 @@ public virtual ComplexCollectionEntry ComplexCollection(string propertyName)
/// examples.
///
public virtual IEnumerable ComplexCollections
- => Metadata.ComplexType.GetComplexProperties().Where(p => p.IsCollection).Select(property => new ComplexCollectionEntry(InternalEntry, property));
+ => Metadata.ComplexType.GetComplexProperties().Where(p => p.IsCollection)
+ .Select(property => new ComplexCollectionEntry(InternalEntry, property));
}
diff --git a/src/EFCore/ChangeTracking/DetectEntityChangesEventArgs.cs b/src/EFCore/ChangeTracking/DetectEntityChangesEventArgs.cs
index 8e8283182a4..daf8cfea94c 100644
--- a/src/EFCore/ChangeTracking/DetectEntityChangesEventArgs.cs
+++ b/src/EFCore/ChangeTracking/DetectEntityChangesEventArgs.cs
@@ -14,7 +14,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
public class DetectEntityChangesEventArgs : DetectChangesEventArgs
{
private readonly InternalEntityEntry _internalEntityEntry;
- private EntityEntry? _entry;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -29,6 +28,7 @@ public DetectEntityChangesEventArgs(InternalEntityEntry internalEntityEntry)
///
/// The for the entity.
///
+ [field: AllowNull, MaybeNull]
public virtual EntityEntry Entry
- => _entry ??= new EntityEntry(_internalEntityEntry);
+ => field ??= new EntityEntry(_internalEntityEntry);
}
diff --git a/src/EFCore/ChangeTracking/DetectedEntityChangesEventArgs.cs b/src/EFCore/ChangeTracking/DetectedEntityChangesEventArgs.cs
index 8d45c6ee6dd..6618495cda9 100644
--- a/src/EFCore/ChangeTracking/DetectedEntityChangesEventArgs.cs
+++ b/src/EFCore/ChangeTracking/DetectedEntityChangesEventArgs.cs
@@ -14,7 +14,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
public class DetectedEntityChangesEventArgs : DetectedChangesEventArgs
{
private readonly InternalEntityEntry _internalEntityEntry;
- private EntityEntry? _entry;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -32,6 +31,7 @@ public DetectedEntityChangesEventArgs(
///
/// The for the entity.
///
+ [field: AllowNull, MaybeNull]
public virtual EntityEntry Entry
- => _entry ??= new EntityEntry(_internalEntityEntry);
+ => field ??= new EntityEntry(_internalEntityEntry);
}
diff --git a/src/EFCore/ChangeTracking/EntityEntry.cs b/src/EFCore/ChangeTracking/EntityEntry.cs
index 91299a60a45..a2d1e5812c7 100644
--- a/src/EFCore/ChangeTracking/EntityEntry.cs
+++ b/src/EFCore/ChangeTracking/EntityEntry.cs
@@ -25,7 +25,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
public class EntityEntry : IInfrastructure
{
private static readonly int MaxEntityState = Enum.GetValuesAsUnderlyingType().Cast().Max();
- private IEntityFinder? _finder;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -277,10 +276,9 @@ public virtual IEnumerable Navigations
var entityType = InternalEntry.EntityType;
return entityType.GetNavigations()
.Concat(entityType.GetSkipNavigations())
- .Select(
- navigation => navigation.IsCollection
- ? (NavigationEntry)new CollectionEntry(InternalEntry, navigation)
- : new ReferenceEntry(InternalEntry, navigation));
+ .Select(navigation => navigation.IsCollection
+ ? (NavigationEntry)new CollectionEntry(InternalEntry, navigation)
+ : new ReferenceEntry(InternalEntry, navigation));
}
}
@@ -367,7 +365,8 @@ public virtual ComplexPropertyEntry ComplexProperty(string propertyName)
/// examples.
///
public virtual IEnumerable ComplexProperties
- => Metadata.GetComplexProperties().Where(p => !p.IsCollection).Select(property => new ComplexPropertyEntry(InternalEntry, property));
+ => Metadata.GetComplexProperties().Where(p => !p.IsCollection)
+ .Select(property => new ComplexPropertyEntry(InternalEntry, property));
///
/// Provides access to change tracking information and operations for a given collection property of a complex type on this entity.
@@ -409,7 +408,8 @@ public virtual ComplexCollectionEntry ComplexCollection(string propertyName)
/// examples.
///
public virtual IEnumerable ComplexCollections
- => Metadata.GetComplexProperties().Where(p => p.IsCollection).Select(property => new ComplexCollectionEntry(InternalEntry, property));
+ => Metadata.GetComplexProperties().Where(p => p.IsCollection)
+ .Select(property => new ComplexCollectionEntry(InternalEntry, property));
///
/// Provides access to change tracking and loading information for a reference (i.e. non-collection)
@@ -696,8 +696,9 @@ private void Reload(PropertyValues? storeValues)
}
}
+ [field: AllowNull, MaybeNull]
private IEntityFinder Finder
- => _finder ??= InternalEntry.StateManager.CreateEntityFinder(InternalEntry.EntityType);
+ => field ??= InternalEntry.StateManager.CreateEntityFinder(InternalEntry.EntityType);
///
/// Returns a string that represents the current object.
diff --git a/src/EFCore/ChangeTracking/EntityEntryEventArgs.cs b/src/EFCore/ChangeTracking/EntityEntryEventArgs.cs
index 41404ca21dc..cbdd9a605eb 100644
--- a/src/EFCore/ChangeTracking/EntityEntryEventArgs.cs
+++ b/src/EFCore/ChangeTracking/EntityEntryEventArgs.cs
@@ -15,7 +15,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
public class EntityEntryEventArgs : EventArgs
{
private readonly InternalEntityEntry _internalEntityEntry;
- private EntityEntry? _entry;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -31,6 +30,7 @@ public EntityEntryEventArgs(
///
/// The for the entity.
///
+ [field: AllowNull, MaybeNull]
public virtual EntityEntry Entry
- => _entry ??= new EntityEntry(_internalEntityEntry);
+ => field ??= new EntityEntry(_internalEntityEntry);
}
diff --git a/src/EFCore/ChangeTracking/EntityEntryGraphNode.cs b/src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
index c4e82161709..a3266adf990 100644
--- a/src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
+++ b/src/EFCore/ChangeTracking/EntityEntryGraphNode.cs
@@ -28,8 +28,7 @@ public class EntityEntryGraphNode : IInfrastructure
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- [DebuggerStepThrough]
- [EntityFrameworkInternal]
+ [DebuggerStepThrough, EntityFrameworkInternal]
public EntityEntryGraphNode(
InternalEntityEntry entry,
InternalEntityEntry? sourceEntry,
diff --git a/src/EFCore/ChangeTracking/EntityEntryGraphNode`.cs b/src/EFCore/ChangeTracking/EntityEntryGraphNode`.cs
index 5758247ee7e..cedbe7e06d8 100644
--- a/src/EFCore/ChangeTracking/EntityEntryGraphNode`.cs
+++ b/src/EFCore/ChangeTracking/EntityEntryGraphNode`.cs
@@ -20,8 +20,7 @@ public class EntityEntryGraphNode : EntityEntryGraphNode
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- [DebuggerStepThrough]
- [EntityFrameworkInternal]
+ [DebuggerStepThrough, EntityFrameworkInternal]
public EntityEntryGraphNode(
InternalEntityEntry entry,
TState state,
diff --git a/src/EFCore/ChangeTracking/GeometryValueComparer.cs b/src/EFCore/ChangeTracking/GeometryValueComparer.cs
index 29594894c2e..1d6a78070ab 100644
--- a/src/EFCore/ChangeTracking/GeometryValueComparer.cs
+++ b/src/EFCore/ChangeTracking/GeometryValueComparer.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking;
///
@@ -12,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
/// See EF Core value comparers for more information and examples.
///
public class GeometryValueComparer
- <[DynamicallyAccessedMembers(
+<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
TGeometry>
@@ -43,7 +41,7 @@ public GeometryValueComparer()
return Expression.Lambda>(
Expression.Block(
typeof(bool),
- new[] { x, y, xNull, yNull },
+ [x, y, xNull, yNull],
Expression.Assign(x, left),
Expression.Assign(y, right),
Expression.Assign(xNull, Expression.ReferenceEqual(x, nullExpression)),
diff --git a/src/EFCore/ChangeTracking/IDependentKeyValueFactory`.cs b/src/EFCore/ChangeTracking/IDependentKeyValueFactory`.cs
index b5640e33cdd..c8a5a151dbf 100644
--- a/src/EFCore/ChangeTracking/IDependentKeyValueFactory`.cs
+++ b/src/EFCore/ChangeTracking/IDependentKeyValueFactory`.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
namespace Microsoft.EntityFrameworkCore.ChangeTracking;
diff --git a/src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs b/src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
index 3c388b510df..e4fe149a005 100644
--- a/src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
+++ b/src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
@@ -41,11 +41,6 @@ public override object ToObject()
var structuralObject = StructuralType.GetOrCreateMaterializer(MaterializerSource)(
new MaterializationContext(new ValueBuffer(_values), InternalEntry.Context));
- if (_complexCollectionValues == null)
- {
- return structuralObject;
- }
-
for (var i = 0; i < _complexCollectionValues.Length; i++)
{
var propertyValuesList = _complexCollectionValues[i];
@@ -54,9 +49,9 @@ public override object ToObject()
continue;
}
-
var complexProperty = ComplexCollectionProperties[i];
- Check.DebugAssert(!complexProperty.IsShadowProperty(),
+ Check.DebugAssert(
+ !complexProperty.IsShadowProperty(),
$"Shadow complex property {complexProperty.Name} is not supported. Issue #31243");
var list = (IList)((IRuntimeComplexProperty)complexProperty).GetIndexedCollectionAccessor().Create(propertyValuesList.Count);
structuralObject = ((IRuntimeComplexProperty)complexProperty).GetSetter().SetClrValue(structuralObject, list);
@@ -138,21 +133,21 @@ public override PropertyValues Clone()
Array.Copy(_values, copies, _values.Length);
var clone = new ArrayPropertyValues(InternalEntry, copies);
- if (_complexCollectionValues != null)
+ for (var i = 0; i < _complexCollectionValues.Length; i++)
{
- for (var i = 0; i < _complexCollectionValues.Length; i++)
+ var list = _complexCollectionValues[i];
+ if (list == null)
{
- var list = _complexCollectionValues[i];
- if (list != null)
- {
- var clonedList = new List();
- foreach (var propertyValues in list)
- {
- clonedList.Add((ArrayPropertyValues?)propertyValues?.Clone());
- }
- clone._complexCollectionValues[i] = clonedList;
- }
+ continue;
+ }
+
+ var clonedList = new List();
+ foreach (var propertyValues in list)
+ {
+ clonedList.Add((ArrayPropertyValues?)propertyValues?.Clone());
}
+
+ clone._complexCollectionValues[i] = clonedList;
}
return clone;
@@ -190,12 +185,12 @@ public override object? this[string propertyName]
{
get
{
- if (StructuralType.FindProperty(propertyName) is IProperty property)
+ if (StructuralType.FindProperty(propertyName) is { } property)
{
return _values[property.GetIndex()];
}
- if (StructuralType.FindComplexProperty(propertyName) is IComplexProperty complexProperty)
+ if (StructuralType.FindComplexProperty(propertyName) is { } complexProperty)
{
return this[complexProperty];
}
@@ -205,33 +200,31 @@ public override object? this[string propertyName]
}
set
{
- if (StructuralType.FindProperty(propertyName) is IProperty property)
+ if (StructuralType.FindProperty(propertyName) is { } property)
{
SetValue(property.GetIndex(), value);
return;
}
- if (StructuralType.FindComplexProperty(propertyName) is IComplexProperty complexProperty)
+ if (StructuralType.FindComplexProperty(propertyName) is { } complexProperty)
{
CheckCollection(complexProperty);
- if (value is null)
- {
- _complexCollectionValues[complexProperty.GetIndex()] = null;
- }
- else if (value is List propertyValuesList)
- {
- _complexCollectionValues[complexProperty.GetIndex()] = propertyValuesList;
- }
- else if (value is IList complexCollection)
+ switch (value)
{
- this[complexProperty] = complexCollection;
- }
- else
- {
- throw new InvalidOperationException(
- CoreStrings.ComplexPropertyValueNotList(
- complexProperty.Name, complexProperty.ClrType, value.GetType().ShortDisplayName()));
+ case null:
+ _complexCollectionValues[complexProperty.GetIndex()] = null;
+ break;
+ case List propertyValuesList:
+ _complexCollectionValues[complexProperty.GetIndex()] = propertyValuesList;
+ break;
+ case IList complexCollection:
+ this[complexProperty] = complexCollection;
+ break;
+ default:
+ throw new InvalidOperationException(
+ CoreStrings.ComplexPropertyValueNotList(
+ complexProperty.Name, complexProperty.ClrType, value.GetType().ShortDisplayName()));
}
}
@@ -269,7 +262,8 @@ public override IList? this[IComplexProperty complexProperty]
return null;
}
- var complexObjectsList = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor().Create(propertyValuesList.Count);
+ var complexObjectsList = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor()
+ .Create(propertyValuesList.Count);
foreach (var propertyValues in propertyValuesList)
{
complexObjectsList.Add(propertyValues?.ToObject());
@@ -281,7 +275,7 @@ public override IList? this[IComplexProperty complexProperty]
set => SetComplexCollectionValue(CheckCollection(complexProperty), GetComplexCollectionPropertyValues(complexProperty, value));
}
- ///
+ ///
public override void SetValues(IDictionary values)
=> SetValuesFromDictionary((IRuntimeTypeBase)StructuralType, Check.NotNull(values));
@@ -308,10 +302,12 @@ private void SetValuesFromDictionary(IRuntimeTypeBase structuralType,
if (complexValue != null && dictionaryList == null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionValueNotDictionaryList(complexProperty.Name, complexValue.GetType().ShortDisplayName()));
+ CoreStrings.ComplexCollectionValueNotDictionaryList(
+ complexProperty.Name, complexValue.GetType().ShortDisplayName()));
}
- SetComplexCollectionValue(complexProperty, CreatePropertyValuesFromDictionaryList(complexProperty, dictionaryList));
+ SetComplexCollectionValue(
+ complexProperty, CreatePropertyValuesFromDictionaryList(complexProperty, dictionaryList));
}
else
{
@@ -330,7 +326,9 @@ private void SetValuesFromDictionary(IRuntimeTypeBase structuralType,
}
}
- private List? CreatePropertyValuesFromDictionaryList(IComplexProperty complexProperty, IList? collection)
+ private List? CreatePropertyValuesFromDictionaryList(
+ IComplexProperty complexProperty,
+ IList? collection)
{
if (collection == null)
{
@@ -387,7 +385,8 @@ public override TValue GetValue(IProperty property)
private void SetValue(int index, object? value)
{
var property = Properties[index];
- Check.DebugAssert(index == property.GetIndex(),
+ Check.DebugAssert(
+ index == property.GetIndex(),
$"Property index {property.GetIndex()} does not match the index {index} for the property {property.Name} in the structural type {StructuralType.DisplayName()}");
if (value != null)
@@ -428,9 +427,7 @@ private IStructuralTypeMaterializerSource MaterializerSource
///
[EntityFrameworkInternal]
internal void SetComplexCollectionValue(IComplexProperty complexProperty, List? propertyValuesList)
- {
- _complexCollectionValues[complexProperty.GetIndex()] = propertyValuesList;
- }
+ => _complexCollectionValues[complexProperty.GetIndex()] = propertyValuesList;
private List? GetComplexCollectionPropertyValues(IComplexProperty complexProperty, IList? collection)
{
@@ -449,7 +446,8 @@ internal void SetComplexCollectionValue(IComplexProperty complexProperty, List(ReferenceEqualityComparer.Instance);
var currentCollection = (IList?)entry[complexProperty];
@@ -327,7 +329,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
var originalCollection = (IList?)entry.GetOriginalValue(complexProperty);
var changesFound = (currentCollection == null) != (originalCollection == null);
- entry.EnsureComplexCollectionEntriesCapacity(complexProperty, currentCollection?.Count ?? 0, originalCollection?.Count ?? 0, trim: false);
+ entry.EnsureComplexCollectionEntriesCapacity(
+ complexProperty, currentCollection?.Count ?? 0, originalCollection?.Count ?? 0, trim: false);
var originalNulls = new HashSet();
var removed = new Dictionary(ReferenceEqualityComparer.Instance);
if (originalCollection != null
@@ -354,7 +357,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
originalEntry.SetEntityState(EntityState.Deleted);
}
- Check.DebugAssert(originalEntry.OriginalOrdinal == i, $"Expected original ordinal {originalEntry.OriginalOrdinal} to be equal to {i}.");
+ Check.DebugAssert(
+ originalEntry.OriginalOrdinal == i, $"Expected original ordinal {originalEntry.OriginalOrdinal} to be equal to {i}.");
originalEntries[element] = originalEntry;
}
@@ -381,7 +385,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
// Existing instance found, fix ordinal and check for changes.
var originalEntry = originalEntries[element];
- Check.DebugAssert(originalEntry.OriginalOrdinal == originalOrdinal,
+ Check.DebugAssert(
+ originalEntry.OriginalOrdinal == originalOrdinal,
$"The OriginalOrdinal for entry of the element at original ordinal {originalOrdinal} is {originalEntry.OriginalOrdinal}.");
if (originalEntry.Ordinal != i)
{
@@ -404,7 +409,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
}
else
{
- Check.DebugAssert(originalEntry.Ordinal > i || currentNulls.Contains(originalEntry.Ordinal),
+ Check.DebugAssert(
+ originalEntry.Ordinal > i || currentNulls.Contains(originalEntry.Ordinal),
$"Expected the entry that was previously at {originalEntry.Ordinal} to have been encountered at an ordinal before {i}.");
entry.MoveComplexCollectionEntry(complexProperty, originalEntry.Ordinal, i);
@@ -461,7 +467,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
nullEntryOrdinal = j;
break;
}
- else if (newEntry.OriginalOrdinal >= (originalCollection?.Count ?? 0)
+
+ if (newEntry.OriginalOrdinal >= (originalCollection?.Count ?? 0)
|| newEntry.EntityState == EntityState.Detached)
{
nullEntryOrdinal = j;
@@ -532,10 +539,12 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
}
else
{
- entry.MoveComplexCollectionEntry(complexProperty, currentEntry.OriginalOrdinal, originalOrdinal, original: true);
+ entry.MoveComplexCollectionEntry(
+ complexProperty, currentEntry.OriginalOrdinal, originalOrdinal, original: true);
}
}
}
+
currentEntry.SetEntityState(originalWasNull ? EntityState.Modified : EntityState.Unchanged);
}
}
@@ -566,7 +575,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
}
else
{
- Check.DebugAssert(false,
+ Check.DebugAssert(
+ false,
$"Expected the entry at {addedOrdinal} to have been removed or matched with a null entry. Current state: {currentEntry.EntityState}.");
currentEntry.SetEntityState(EntityState.Added);
@@ -589,7 +599,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
foreach (var (removedElement, originalOrdinal) in removed)
{
var originalEntry = originalEntries[removedElement];
- Check.DebugAssert(originalEntry.OriginalOrdinal == originalOrdinal,
+ Check.DebugAssert(
+ originalEntry.OriginalOrdinal == originalOrdinal,
$"The OriginalOrdinal for entry of the element at original ordinal {originalOrdinal} is {originalEntry.OriginalOrdinal}.");
var newCurrentOrdinal = originalEntry.Ordinal;
if (originalEntry.EntityState is EntityState.Unchanged or EntityState.Modified or EntityState.Detached)
@@ -639,6 +650,7 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
}
}
}
+
changesFound = true;
}
@@ -676,7 +688,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
continue;
}
- Check.DebugAssert(nullEntry.EntityState is EntityState.Deleted or EntityState.Detached,
+ Check.DebugAssert(
+ nullEntry.EntityState is EntityState.Deleted or EntityState.Detached,
$"Expected null entry at {originalNull} to be deleted or detached, current state {nullEntry.EntityState}.");
nullEntry.SetEntityState(EntityState.Deleted);
changesFound = true;
@@ -694,7 +707,8 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
continue;
}
- Check.DebugAssert(nullEntry.EntityState is EntityState.Added or EntityState.Detached,
+ Check.DebugAssert(
+ nullEntry.EntityState is EntityState.Added or EntityState.Detached,
$"Expected null entry at {currentNull} to be added or detached, current state {nullEntry.EntityState}.");
nullEntry.SetEntityState(EntityState.Added);
changesFound = true;
@@ -702,11 +716,12 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
}
// Trim excess entries
- entry.EnsureComplexCollectionEntriesCapacity(complexProperty, currentCollection?.Count ?? 0, originalCollection?.Count ?? 0, trim: true);
+ entry.EnsureComplexCollectionEntriesCapacity(
+ complexProperty, currentCollection?.Count ?? 0, originalCollection?.Count ?? 0, trim: true);
if (changesFound)
{
- entry.SetPropertyModified(complexProperty, true);
+ entry.SetPropertyModified(complexProperty);
}
return changesFound;
diff --git a/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs b/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs
index 072f817e3e3..23988df8884 100644
--- a/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
diff --git a/src/EFCore/ChangeTracking/Internal/ConvertingValueComparer.cs b/src/EFCore/ChangeTracking/Internal/ConvertingValueComparer.cs
index d02486cc887..be221c8a40a 100644
--- a/src/EFCore/ChangeTracking/Internal/ConvertingValueComparer.cs
+++ b/src/EFCore/ChangeTracking/Internal/ConvertingValueComparer.cs
@@ -1,10 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
+using static System.Linq.Expressions.Expression;
-using System.Diagnostics.CodeAnalysis;
-using static Expression;
+namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
/// A composable value comparer that accepts a value comparer, and exposes it as a value comparer for a base type.
@@ -17,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public class ConvertingValueComparer
- <[DynamicallyAccessedMembers(
+<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
TTo, TFrom> : ValueComparer, IInfrastructure
diff --git a/src/EFCore/ChangeTracking/Internal/DependentKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/DependentKeyValueFactory.cs
index 412b640544b..bd1379d562a 100644
--- a/src/EFCore/ChangeTracking/Internal/DependentKeyValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/DependentKeyValueFactory.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
diff --git a/src/EFCore/ChangeTracking/Internal/DependentsMap.cs b/src/EFCore/ChangeTracking/Internal/DependentsMap.cs
index 42f6d6027a9..ae891a0f204 100644
--- a/src/EFCore/ChangeTracking/Internal/DependentsMap.cs
+++ b/src/EFCore/ChangeTracking/Internal/DependentsMap.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
diff --git a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs
index 26905ffd1c7..9e0264e594c 100644
--- a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs
+++ b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
@@ -250,7 +248,7 @@ var numberOfStates
case 1 when returnDeleted:
return _deletedReferenceMap!.Values;
case 0:
- return Enumerable.Empty();
+ return [];
}
}
diff --git a/src/EFCore/ChangeTracking/Internal/EntryPropertyValues.cs b/src/EFCore/ChangeTracking/Internal/EntryPropertyValues.cs
index 0c1d989c68d..bae89bf32a6 100644
--- a/src/EFCore/ChangeTracking/Internal/EntryPropertyValues.cs
+++ b/src/EFCore/ChangeTracking/Internal/EntryPropertyValues.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
@@ -155,7 +154,8 @@ private void SetValuesFromDto(InternalEntryBase entry, IRuntimeTypeBase structur
var item = dtoList[i];
if (item != null)
{
- SetValuesFromDto(GetComplexCollectionEntry(entry, complexProperty, i), (IRuntimeComplexType)complexProperty.ComplexType, item);
+ SetValuesFromDto(
+ GetComplexCollectionEntry(entry, complexProperty, i), (IRuntimeComplexType)complexProperty.ComplexType, item);
}
}
}
@@ -219,7 +219,8 @@ private void SetValuesFromDto(InternalEntryBase entry, IRuntimeTypeBase structur
continue;
}
- var nestedCollection = (IList)((IRuntimePropertyBase)nestedComplexProperty).GetIndexedCollectionAccessor().Create(nestedList.Count);
+ var nestedCollection = (IList)((IRuntimePropertyBase)nestedComplexProperty).GetIndexedCollectionAccessor()
+ .Create(nestedList.Count);
for (var i = 0; i < nestedList.Count; i++)
{
var nestedDtoItem = nestedList[i];
@@ -229,7 +230,8 @@ private void SetValuesFromDto(InternalEntryBase entry, IRuntimeTypeBase structur
}
else
{
- var nestedComplexObject = CreateComplexObjectFromDto((IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedDtoItem);
+ var nestedComplexObject = CreateComplexObjectFromDto(
+ (IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedDtoItem);
nestedCollection.Add(nestedComplexObject);
}
}
@@ -314,11 +316,14 @@ public override void SetValues(PropertyValues propertyValues)
}
}
- ///
+ ///
public override void SetValues(IDictionary values)
=> SetValuesFromDictionary(InternalEntry, (IRuntimeTypeBase)StructuralType, Check.NotNull(values));
- private void SetValuesFromDictionary(InternalEntryBase entry, IRuntimeTypeBase structuralType, IDictionary values)
+ private void SetValuesFromDictionary(
+ InternalEntryBase entry,
+ IRuntimeTypeBase structuralType,
+ IDictionary values)
{
foreach (var property in structuralType.GetProperties())
{
@@ -341,13 +346,15 @@ private void SetValuesFromDictionary(InternalEntryBase entry, IRuntim
if (complexValue != null && dictionaryList == null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionValueNotDictionaryList(complexProperty.Name, complexValue.GetType().ShortDisplayName()));
+ CoreStrings.ComplexCollectionValueNotDictionaryList(
+ complexProperty.Name, complexValue.GetType().ShortDisplayName()));
}
IList? complexList = null;
if (dictionaryList != null)
{
- complexList = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor().Create(dictionaryList.Count);
+ complexList = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor()
+ .Create(dictionaryList.Count);
for (var i = 0; i < dictionaryList.Count; i++)
{
var item = dictionaryList[i];
@@ -355,8 +362,10 @@ private void SetValuesFromDictionary(InternalEntryBase entry, IRuntim
if (item != null && itemDict == null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionValueNotDictionaryList(complexProperty.Name, item.GetType().ShortDisplayName()));
+ CoreStrings.ComplexCollectionValueNotDictionaryList(
+ complexProperty.Name, item.GetType().ShortDisplayName()));
}
+
complexList.Add(CreateComplexObjectFromDictionary((IRuntimeComplexType)complexProperty.ComplexType, itemDict));
}
}
@@ -416,12 +425,12 @@ public override object? this[string propertyName]
{
get
{
- if (StructuralType.FindProperty(propertyName) is IProperty property)
+ if (StructuralType.FindProperty(propertyName) is { } property)
{
return GetValueInternal(InternalEntry, property);
}
- if (StructuralType.FindComplexProperty(propertyName) is IComplexProperty complexProperty)
+ if (StructuralType.FindComplexProperty(propertyName) is { } complexProperty)
{
return GetValueInternal(InternalEntry, complexProperty);
}
@@ -431,13 +440,13 @@ public override object? this[string propertyName]
}
set
{
- if (StructuralType.FindProperty(propertyName) is IProperty property)
+ if (StructuralType.FindProperty(propertyName) is { } property)
{
SetValueInternal(InternalEntry, property, value);
return;
}
- if (StructuralType.FindComplexProperty(propertyName) is IComplexProperty complexProperty)
+ if (StructuralType.FindComplexProperty(propertyName) is { } complexProperty)
{
SetValueInternal(InternalEntry, complexProperty, value);
return;
@@ -491,7 +500,9 @@ public override IList? this[IComplexProperty complexProperty]
///
/// Creates a complex object from a dictionary of property values using EF's property accessors.
///
- private object? CreateComplexObjectFromDictionary(IRuntimeComplexType complexType, IDictionary? dictionary)
+ private object? CreateComplexObjectFromDictionary(
+ IRuntimeComplexType complexType,
+ IDictionary? dictionary)
{
if (dictionary == null)
{
@@ -522,20 +533,22 @@ public override IList? this[IComplexProperty complexProperty]
{
if (nestedComplexProperty.IsCollection && nestedValue is IList nestedList)
{
- var nestedCollection = (IList)((IRuntimePropertyBase)nestedComplexProperty).GetIndexedCollectionAccessor().Create(nestedList.Count);
+ var nestedCollection = (IList)((IRuntimePropertyBase)nestedComplexProperty).GetIndexedCollectionAccessor()
+ .Create(nestedList.Count);
foreach (var nestedItem in nestedList)
{
- nestedCollection.Add(nestedItem switch
- {
- null => null,
- IDictionary nestedItemDict
- => CreateComplexObjectFromDictionary(
- (IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedItemDict),
- _ => throw new InvalidOperationException(
- CoreStrings.ComplexCollectionValueNotDictionaryList(
- nestedComplexProperty.Name, nestedList.GetType().ShortDisplayName()))
- });
+ nestedCollection.Add(
+ nestedItem switch
+ {
+ null => null,
+ IDictionary nestedItemDict
+ => CreateComplexObjectFromDictionary(
+ (IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedItemDict),
+ _ => throw new InvalidOperationException(
+ CoreStrings.ComplexCollectionValueNotDictionaryList(
+ nestedComplexProperty.Name, nestedList.GetType().ShortDisplayName()))
+ });
}
var propertyInfo = nestedComplexProperty.PropertyInfo;
@@ -547,19 +560,22 @@ IDictionary nestedItemDict
else if (nestedComplexProperty.IsCollection && nestedValue != null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionValueNotDictionaryList(nestedComplexProperty.Name, nestedValue.GetType().ShortDisplayName()));
+ CoreStrings.ComplexCollectionValueNotDictionaryList(
+ nestedComplexProperty.Name, nestedValue.GetType().ShortDisplayName()));
}
else if (!nestedComplexProperty.IsCollection)
{
object? nestedComplexObject = null;
if (nestedValue is IDictionary nestedDict)
{
- nestedComplexObject = CreateComplexObjectFromDictionary((IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedDict);
+ nestedComplexObject = CreateComplexObjectFromDictionary(
+ (IRuntimeComplexType)nestedComplexProperty.ComplexType, nestedDict);
}
else if (nestedValue != null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexPropertyValueNotDictionary(nestedComplexProperty.Name, nestedValue.GetType().ShortDisplayName()));
+ CoreStrings.ComplexPropertyValueNotDictionary(
+ nestedComplexProperty.Name, nestedValue.GetType().ShortDisplayName()));
}
var propertyInfo = nestedComplexProperty.PropertyInfo;
diff --git a/src/EFCore/ChangeTracking/Internal/IInternalEntry.cs b/src/EFCore/ChangeTracking/Internal/IInternalEntry.cs
index a6c24262cb9..357d258e532 100644
--- a/src/EFCore/ChangeTracking/Internal/IInternalEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/IInternalEntry.cs
@@ -67,7 +67,8 @@ public interface IInternalEntry
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public object Entity => EntityEntry.Entity;
+ public object Entity
+ => EntityEntry.Entity;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -331,7 +332,12 @@ public interface IInternalEntry
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- void SetProperty(IPropertyBase propertyBase, object? value, bool isMaterialization, bool setModified = true, bool isCascadeDelete = false);
+ void SetProperty(
+ IPropertyBase propertyBase,
+ object? value,
+ bool isMaterialization,
+ bool setModified = true,
+ bool isCascadeDelete = false);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -339,7 +345,12 @@ public interface IInternalEntry
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- void SetPropertyModified(IProperty property, bool changeState = true, bool isModified = true, bool isConceptualNull = false, bool acceptChanges = false);
+ void SetPropertyModified(
+ IProperty property,
+ bool changeState = true,
+ bool isModified = true,
+ bool isConceptualNull = false,
+ bool acceptChanges = false);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore/ChangeTracking/Internal/InternalComplexEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalComplexEntry.cs
index 5b8be17c366..66a06c7a841 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalComplexEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalComplexEntry.cs
@@ -14,9 +14,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
public sealed class InternalComplexEntry : InternalEntryBase
{
- private int _ordinal;
- private int _originalOrdinal;
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -32,7 +29,7 @@ public InternalComplexEntry(
Check.DebugAssert(complexType.ComplexProperty.IsCollection, $"{complexType} expected to be a collection");
ContainingEntry = containingEntry;
- _ordinal = ordinal;
+ Ordinal = ordinal;
OriginalOrdinal = ordinal;
}
@@ -64,7 +61,8 @@ public override InternalEntityEntry EntityEntry
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public IComplexProperty ComplexProperty => ComplexType.ComplexProperty;
+ public IComplexProperty ComplexProperty
+ => ComplexType.ComplexProperty;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -72,7 +70,8 @@ public override InternalEntityEntry EntityEntry
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override IStateManager StateManager => ContainingEntry.StateManager;
+ public override IStateManager StateManager
+ => ContainingEntry.StateManager;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -98,20 +97,21 @@ public override IReadOnlyList GetOrdinals()
public int Ordinal
{
// -1 is used to indicate that the entry is deleted
- get => _ordinal;
+ get;
set
{
if (EntityState is not EntityState.Detached and not EntityState.Deleted
- && _ordinal != value
+ && field != value
&& ContainingEntry.GetComplexCollectionEntry(ComplexProperty, value) is var existingEntry
&& existingEntry != this
&& existingEntry is { EntityState: not EntityState.Detached and not EntityState.Deleted, Ordinal: not -1 })
{
- throw new InvalidOperationException(CoreStrings.ComplexCollectionEntryOrdinalReadOnly(
- ComplexProperty.DeclaringType.ShortNameChain(), ComplexProperty.Name));
+ throw new InvalidOperationException(
+ CoreStrings.ComplexCollectionEntryOrdinalReadOnly(
+ ComplexProperty.DeclaringType.ShortNameChain(), ComplexProperty.Name));
}
- _ordinal = value;
+ field = value;
}
}
@@ -121,7 +121,8 @@ public int Ordinal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public IRuntimeComplexType ComplexType => (IRuntimeComplexType)StructuralType;
+ public IRuntimeComplexType ComplexType
+ => (IRuntimeComplexType)StructuralType;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -132,20 +133,21 @@ public int Ordinal
public int OriginalOrdinal
{
// -1 is used to indicate that the entry is added
- get => _originalOrdinal;
+ get;
set
{
if (EntityState is not EntityState.Detached and not EntityState.Added
- && _originalOrdinal != value
+ && field != value
&& ContainingEntry.GetComplexCollectionOriginalEntry(ComplexProperty, value) is var existingEntry
&& existingEntry != this
&& existingEntry is { EntityState: not EntityState.Detached and not EntityState.Added, OriginalOrdinal: not -1 })
{
- throw new InvalidOperationException(CoreStrings.ComplexCollectionEntryOriginalOrdinalReadOnly(
- ComplexProperty.DeclaringType.ShortNameChain(), ComplexProperty.Name));
+ throw new InvalidOperationException(
+ CoreStrings.ComplexCollectionEntryOriginalOrdinalReadOnly(
+ ComplexProperty.DeclaringType.ShortNameChain(), ComplexProperty.Name));
}
- _originalOrdinal = value;
+ field = value;
}
}
@@ -157,8 +159,8 @@ public int OriginalOrdinal
///
public override object? ReadPropertyValue(IPropertyBase propertyBase)
=> EntityState == EntityState.Deleted
- ? GetOriginalValue(propertyBase)
- : base.ReadPropertyValue(propertyBase);
+ ? GetOriginalValue(propertyBase)
+ : base.ReadPropertyValue(propertyBase);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -168,8 +170,8 @@ public int OriginalOrdinal
///
public override T ReadOriginalValue(IProperty property, int originalValueIndex)
=> EntityState == EntityState.Added
- ? GetCurrentValue(property)
- : base.ReadOriginalValue(property, originalValueIndex);
+ ? GetCurrentValue(property)
+ : base.ReadOriginalValue(property, originalValueIndex);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -179,8 +181,8 @@ public override T ReadOriginalValue(IProperty property, int originalValueInde
///
public override object? GetOriginalValue(IPropertyBase propertyBase)
=> EntityState == EntityState.Added
- ? GetCurrentValue(propertyBase)
- : base.GetOriginalValue(propertyBase);
+ ? GetCurrentValue(propertyBase)
+ : base.GetOriginalValue(propertyBase);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -301,7 +303,7 @@ public string GetPropertyPath(bool withElement = true)
}
private static string GetShortNameChain(IReadOnlyTypeBase structuralType)
- => (structuralType is IReadOnlyComplexType complexType) && (complexType.ComplexProperty is IReadOnlyComplexProperty complexProperty)
+ => (structuralType is IReadOnlyComplexType { ComplexProperty: var complexProperty })
? complexProperty.IsCollection
? ""
: GetShortNameChain(complexProperty.DeclaringType) + "." + complexProperty.Name + "."
@@ -327,13 +329,11 @@ public DebugView DebugView
() => ToDebugString(ChangeTrackerDebugStringOptions.ShortDefault),
() => ToDebugString());
-
private string ToDebugString(
ChangeTrackerDebugStringOptions options = ChangeTrackerDebugStringOptions.LongDefault,
int indent = 0)
{
var builder = new StringBuilder();
- var indentString = new string(' ', indent);
try
{
diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
index 411e875575a..9af4a68e45a 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
@@ -3,7 +3,6 @@
using System.Collections.Specialized;
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
@@ -106,7 +105,8 @@ public InternalEntityEntry(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public IRuntimeEntityType EntityType => (IRuntimeEntityType)StructuralType;
+ public IRuntimeEntityType EntityType
+ => (IRuntimeEntityType)StructuralType;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -467,7 +467,6 @@ public void PropagateValue(
}
}
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -489,7 +488,7 @@ public override void AcceptChanges()
}
private static readonly MethodInfo ReadRelationshipSnapshotValueMethod
- = typeof(InternalEntityEntry).GetMethod(nameof(InternalEntityEntry.ReadRelationshipSnapshotValue))!;
+ = typeof(InternalEntityEntry).GetMethod(nameof(ReadRelationshipSnapshotValue))!;
[UnconditionalSuppressMessage(
"ReflectionAnalysis", "IL2060",
@@ -525,7 +524,6 @@ public TProperty GetRelationshipSnapshotValue(IPropertyBase propertyB
public object? GetRelationshipSnapshotValue(IPropertyBase propertyBase)
=> _relationshipsSnapshot.GetValue(this, propertyBase);
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -678,7 +676,6 @@ protected override void OnPropertyChanged(IPropertyBase propertyBase, object? va
base.OnPropertyChanged(propertyBase, value, setModified);
}
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -765,10 +762,9 @@ public override void HandleConceptualNulls(bool sensitiveLoggingEnabled, bool fo
}
else
{
- var property = EntityType.GetFlattenedProperties().FirstOrDefault(
- p => (EntityState != EntityState.Modified
- || IsModified(p))
- && PropertyStateData.IsPropertyFlagged(p.GetIndex(), PropertyFlag.Null));
+ var property = EntityType.GetFlattenedProperties().FirstOrDefault(p => (EntityState != EntityState.Modified
+ || IsModified(p))
+ && PropertyStateData.IsPropertyFlagged(p.GetIndex(), PropertyFlag.Null));
if (property != null)
{
@@ -778,7 +774,7 @@ public override void HandleConceptualNulls(bool sensitiveLoggingEnabled, bool fo
CoreStrings.PropertyConceptualNullSensitive(
property.Name,
EntityType.DisplayName(),
- this.BuildOriginalValuesString(new[] { property })));
+ this.BuildOriginalValuesString([property])));
}
throw new InvalidOperationException(
@@ -964,13 +960,13 @@ public void HandleINotifyCollectionChanged(
this,
navigation,
eventArgs.NewItems!.OfType(),
- Enumerable.Empty());
+ []);
break;
case NotifyCollectionChangedAction.Remove:
StateManager.InternalEntityEntryNotifier.NavigationCollectionChanged(
this,
navigation,
- Enumerable.Empty(),
+ [],
eventArgs.OldItems!.OfType());
break;
case NotifyCollectionChangedAction.Replace:
diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs
index 7ad99221396..93f2cb812fe 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs
@@ -123,24 +123,22 @@ private struct InternalComplexCollectionEntry(InternalEntryBase entry, IComplexP
return _originalEntries;
}
- else
+
+ _entries ??= new List(capacity);
+ for (var i = _entries.Count; i < capacity; i++)
{
- _entries ??= new List(capacity);
- for (var i = _entries.Count; i < capacity; i++)
- {
- _entries.Add(null);
- }
+ _entries.Add(null);
+ }
- if (trim)
+ if (trim)
+ {
+ for (var i = _entries.Count - 1; i >= capacity; i--)
{
- for (var i = _entries.Count - 1; i >= capacity; i--)
- {
- _entries.RemoveAt(i);
- }
+ _entries.RemoveAt(i);
}
-
- return _entries;
}
+
+ return _entries;
}
public void AcceptChanges()
@@ -157,6 +155,7 @@ public void AcceptChanges()
{
continue;
}
+
entry.AcceptChanges();
// The entry was deleted, so AcceptChanges removed it from the list
i--;
@@ -171,6 +170,7 @@ public void AcceptChanges()
{
_originalEntries.Add(_entries[i]);
}
+
for (var i = 0; i < _originalEntries.Count; i++)
{
_originalEntries[i]?.AcceptChanges();
@@ -204,10 +204,12 @@ public void RejectChanges()
{
_entries ??= new List(_originalEntries.Count);
_entries.Clear();
+ // ReSharper disable once ForCanBeConvertedToForeach
for (var i = 0; i < _originalEntries.Count; i++)
{
_entries.Add(_originalEntries[i]);
}
+
foreach (var entry in _entries)
{
entry?.Ordinal = entry.OriginalOrdinal;
@@ -226,13 +228,15 @@ public InternalComplexEntry GetEntry(int ordinal, bool original = false)
if (_containingEntry.EntityState == EntityState.Added)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionOriginalEntryAddedEntity(ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
+ CoreStrings.ComplexCollectionOriginalEntryAddedEntity(
+ ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
}
if (_containingEntry.GetOriginalValue(_complexCollection) == null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionEntryOriginalNull(_complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
+ CoreStrings.ComplexCollectionEntryOriginalNull(
+ _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
}
}
else
@@ -240,24 +244,27 @@ public InternalComplexEntry GetEntry(int ordinal, bool original = false)
if (_containingEntry.EntityState == EntityState.Deleted)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionEntryDeletedEntity(ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
+ CoreStrings.ComplexCollectionEntryDeletedEntity(
+ ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
}
if (_containingEntry[_complexCollection] == null)
{
throw new InvalidOperationException(
- CoreStrings.ComplexCollectionNotInitialized(_complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
+ CoreStrings.ComplexCollectionNotInitialized(
+ _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name));
}
}
var entries = GetOrCreateEntries(original);
if (ordinal < 0 || ordinal >= entries.Count)
{
- throw new InvalidOperationException(original
- ? CoreStrings.ComplexCollectionEntryOriginalOrdinalInvalid(
- ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name, entries.Count)
- : CoreStrings.ComplexCollectionEntryOrdinalInvalid(
- ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name, entries.Count));
+ throw new InvalidOperationException(
+ original
+ ? CoreStrings.ComplexCollectionEntryOriginalOrdinalInvalid(
+ ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name, entries.Count)
+ : CoreStrings.ComplexCollectionEntryOrdinalInvalid(
+ ordinal, _complexCollection.DeclaringType.ShortNameChain(), _complexCollection.Name, entries.Count));
}
var complexEntry = entries[ordinal];
@@ -279,9 +286,12 @@ public readonly void MoveEntry(int fromOrdinal, int toOrdinal, bool original = f
}
var entries = original ? _originalEntries : _entries;
- Check.DebugAssert(entries != null, $"Property {_complexCollection.Name} should have{(original ? " original" : "")} entries initialized.");
- if (fromOrdinal < 0 || fromOrdinal >= entries.Count
- || toOrdinal < 0 || toOrdinal >= entries.Count)
+ Check.DebugAssert(
+ entries != null, $"Property {_complexCollection.Name} should have{(original ? " original" : "")} entries initialized.");
+ if (fromOrdinal < 0
+ || fromOrdinal >= entries.Count
+ || toOrdinal < 0
+ || toOrdinal >= entries.Count)
{
throw new ArgumentOutOfRangeException(
CoreStrings.ComplexCollectionMoveInvalidOrdinals(fromOrdinal, toOrdinal, entries.Count));
@@ -350,9 +360,11 @@ public void SetState(EntityState oldState, EntityState newState, bool acceptChan
setOriginalState = true;
}
- EnsureCapacity(((IList?)_containingEntry.GetOriginalValue(_complexCollection))?.Count ?? 0,
+ EnsureCapacity(
+ ((IList?)_containingEntry.GetOriginalValue(_complexCollection))?.Count ?? 0,
original: true, trim: false);
- EnsureCapacity(((IList?)_containingEntry[_complexCollection])?.Count ?? 0,
+ EnsureCapacity(
+ ((IList?)_containingEntry[_complexCollection])?.Count ?? 0,
original: false, trim: false);
var defaultState = newState == EntityState.Modified && !modifyProperties
@@ -397,11 +409,14 @@ public readonly int ValidateOrdinal(InternalComplexEntry entry, bool original, L
if (ordinal < 0 || ordinal >= entries.Count)
{
var property = entry.ComplexProperty;
- throw new InvalidOperationException(original
- ? CoreStrings.ComplexCollectionEntryOriginalOrdinalInvalid(
- ordinal, property.ComplexType.ShortNameChain(), property.Name, ((IList?)_containingEntry.GetOriginalValue(_complexCollection))?.Count ?? 0)
- : CoreStrings.ComplexCollectionEntryOrdinalInvalid(
- ordinal, property.ComplexType.ShortNameChain(), property.Name, ((IList?)_containingEntry.GetCurrentValue(_complexCollection))?.Count ?? 0));
+ throw new InvalidOperationException(
+ original
+ ? CoreStrings.ComplexCollectionEntryOriginalOrdinalInvalid(
+ ordinal, property.ComplexType.ShortNameChain(), property.Name,
+ ((IList?)_containingEntry.GetOriginalValue(_complexCollection))?.Count ?? 0)
+ : CoreStrings.ComplexCollectionEntryOrdinalInvalid(
+ ordinal, property.ComplexType.ShortNameChain(), property.Name,
+ ((IList?)_containingEntry.GetCurrentValue(_complexCollection))?.Count ?? 0));
}
return ordinal;
@@ -439,7 +454,7 @@ public void HandleStateChange(InternalComplexEntry entry, EntityState oldState,
}
}
else if (oldState == EntityState.Added
- && newState is not EntityState.Detached)
+ && newState is not EntityState.Detached)
{
InsertEntry(entry, original: true);
}
@@ -465,6 +480,7 @@ public void HandleStateChange(InternalComplexEntry entry, EntityState oldState,
{
_containingEntry.SetPropertyModified(property, false);
}
+
break;
case EntityState.Deleted:
if (oldState is not EntityState.Detached
@@ -472,8 +488,9 @@ public void HandleStateChange(InternalComplexEntry entry, EntityState oldState,
{
RemoveEntry(entry, original: false);
}
+
entry.Ordinal = -1;
- _containingEntry.SetPropertyModified(property, true);
+ _containingEntry.SetPropertyModified(property);
break;
case EntityState.Added:
if (oldState is not EntityState.Detached
@@ -481,18 +498,22 @@ public void HandleStateChange(InternalComplexEntry entry, EntityState oldState,
{
RemoveEntry(entry, original: true);
}
+
entry.OriginalOrdinal = -1;
- _containingEntry.SetPropertyModified(property, true);
+ _containingEntry.SetPropertyModified(property);
break;
case EntityState.Modified:
- _containingEntry.SetPropertyModified(property, true);
+ _containingEntry.SetPropertyModified(property);
break;
case EntityState.Unchanged:
- if (GetOrCreateEntries(original: false).All(e => e == null || (e.EntityState == EntityState.Unchanged && e.Ordinal == e.OriginalOrdinal))
- && GetOrCreateEntries(original: true).All(e => e == null || (e.EntityState == EntityState.Unchanged && e.Ordinal == e.OriginalOrdinal)))
+ if (GetOrCreateEntries(original: false).All(e
+ => e == null || (e.EntityState == EntityState.Unchanged && e.Ordinal == e.OriginalOrdinal))
+ && GetOrCreateEntries(original: true).All(e
+ => e == null || (e.EntityState == EntityState.Unchanged && e.Ordinal == e.OriginalOrdinal)))
{
_containingEntry.SetPropertyModified(property, false);
}
+
break;
}
@@ -502,18 +523,23 @@ public void HandleStateChange(InternalComplexEntry entry, EntityState oldState,
if (newState is not EntityState.Detached and not EntityState.Deleted)
{
var currentOrdinal = entry.Ordinal;
- Check.DebugAssert(currentOrdinal >= 0 && currentOrdinal < currentEntries.Count,
- $"ComplexEntry ordinal {currentOrdinal} is invalid for property {property.Name}.");
- Check.DebugAssert(currentEntries[currentOrdinal] == entry, $"ComplexEntry at ordinal {currentOrdinal} does not match the provided entry for property {property.Name}.");
+ Check.DebugAssert(
+ currentOrdinal >= 0 && currentOrdinal < currentEntries.Count,
+ $"ComplexEntry ordinal {currentOrdinal} is invalid for property {property.Name}.");
+ Check.DebugAssert(
+ currentEntries[currentOrdinal] == entry,
+ $"ComplexEntry at ordinal {currentOrdinal} does not match the provided entry for property {property.Name}.");
}
var originalEntries = GetOrCreateEntries(original: true);
if (newState is not EntityState.Detached and not EntityState.Added)
{
var originalOrdinal = entry.OriginalOrdinal;
- Check.DebugAssert(originalOrdinal >= 0 && originalOrdinal < originalEntries.Count,
+ Check.DebugAssert(
+ originalOrdinal >= 0 && originalOrdinal < originalEntries.Count,
$"ComplexEntry original ordinal {originalOrdinal} is invalid for property {property.Name}.");
- Check.DebugAssert(originalEntries[originalOrdinal] == entry,
+ Check.DebugAssert(
+ originalEntries[originalOrdinal] == entry,
$"ComplexEntry at OriginalOrdinal {originalOrdinal} does not match the provided entry for property {property.Name}.");
}
}
@@ -627,7 +653,7 @@ public readonly void InsertEntry(InternalComplexEntry entry, bool original = fal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public readonly override string ToString()
+ public override readonly string ToString()
=> ToDebugString(ChangeTrackerDebugStringOptions.ShortDefault);
///
@@ -636,14 +662,15 @@ public readonly override string ToString()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
+ // ReSharper disable once UnusedMember.Local
public readonly DebugView DebugView
{
get
{
var instance = this;
return new DebugView(
- () => instance.ToDebugString(ChangeTrackerDebugStringOptions.ShortDefault),
- () => instance.ToDebugString());
+ () => instance.ToDebugString(ChangeTrackerDebugStringOptions.ShortDefault),
+ () => instance.ToDebugString());
}
}
diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.StateData.cs b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.StateData.cs
index ff811f16e9f..1a1eed21824 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.StateData.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.StateData.cs
@@ -44,6 +44,7 @@ protected internal enum PropertyFlag
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
IsLoaded = 3,
+
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -51,6 +52,7 @@ protected internal enum PropertyFlag
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
IsTemporary = 4,
+
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs
index d81686ad029..ac2b693833e 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
@@ -107,7 +106,8 @@ public DbContext Context
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual InternalEntryBase ContainingEntry => this;
+ public virtual InternalEntryBase ContainingEntry
+ => this;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -115,7 +115,8 @@ public DbContext Context
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual InternalEntityEntry EntityEntry => (InternalEntityEntry)this;
+ public virtual InternalEntityEntry EntityEntry
+ => (InternalEntityEntry)this;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -140,7 +141,8 @@ public virtual EntityState EntityState
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual IReadOnlyList GetOrdinals() => [];
+ public virtual IReadOnlyList GetOrdinals()
+ => [];
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -148,7 +150,8 @@ public virtual EntityState EntityState
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected virtual ref StateData PropertyStateData => ref _stateData;
+ protected virtual ref StateData PropertyStateData
+ => ref _stateData;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -364,7 +367,8 @@ public virtual void MarkUnchangedFromQuery()
{
if (complexCollection.IsCollection)
{
- _complexCollectionEntries[complexCollection.GetIndex()].SetState(EntityState.Detached, EntityState.Unchanged, acceptChanges: false, modifyProperties: false);
+ _complexCollectionEntries[complexCollection.GetIndex()].SetState(
+ EntityState.Detached, EntityState.Unchanged, acceptChanges: false, modifyProperties: false);
}
}
}
@@ -511,7 +515,8 @@ public void SetPropertyModified(
&& changeState
&& !isModified
&& !_stateData.AnyPropertiesFlagged(PropertyFlag.Modified)
- && StructuralType.GetFlattenedComplexProperties().All(p => !p.IsCollection || !_complexCollectionEntries[p.GetIndex()].IsModified()))
+ && StructuralType.GetFlattenedComplexProperties()
+ .All(p => !p.IsCollection || !_complexCollectionEntries[p.GetIndex()].IsModified()))
{
OnStateChanging(EntityState.Unchanged);
_stateData.EntityState = EntityState.Unchanged;
@@ -532,7 +537,7 @@ public bool IsModified(IComplexProperty property)
return property.IsCollection
? _complexCollectionEntries[property.GetIndex()].IsModified()
: property.ComplexType.GetFlattenedProperties().Any(IsModified)
- || property.ComplexType.GetFlattenedComplexProperties().Any(cp => cp.IsCollection && IsModified(cp));
+ || property.ComplexType.GetFlattenedComplexProperties().Any(cp => cp.IsCollection && IsModified(cp));
}
///
@@ -596,7 +601,8 @@ public virtual void OnComplexPropertyModified(IComplexProperty property, bool is
else if (currentState == EntityState.Modified
&& !isModified
&& !_stateData.AnyPropertiesFlagged(PropertyFlag.Modified)
- && StructuralType.GetFlattenedComplexProperties().All(p => !p.IsCollection || !_complexCollectionEntries[p.GetIndex()].IsModified()))
+ && StructuralType.GetFlattenedComplexProperties()
+ .All(p => !p.IsCollection || !_complexCollectionEntries[p.GetIndex()].IsModified()))
{
OnStateChanging(EntityState.Unchanged);
_stateData.EntityState = EntityState.Unchanged;
@@ -650,10 +656,10 @@ protected virtual CurrentValueType GetValueType(IProperty property)
StructuralType.CheckContains(property);
return _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsStoreGenerated)
- ? CurrentValueType.StoreGenerated
- : _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsTemporary)
- ? CurrentValueType.Temporary
- : CurrentValueType.Normal;
+ ? CurrentValueType.StoreGenerated
+ : _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsTemporary)
+ ? CurrentValueType.Temporary
+ : CurrentValueType.Normal;
}
///
@@ -898,8 +904,8 @@ private void WritePropertyValue(
///
public object? GetCurrentValue(IPropertyBase propertyBase)
=> StructuralType.CheckContains(propertyBase) is not IProperty property || !IsConceptualNull(property)
- ? this[propertyBase]
- : null;
+ ? this[propertyBase]
+ : null;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -909,8 +915,8 @@ private void WritePropertyValue(
///
public object? GetPreStoreGeneratedCurrentValue(IPropertyBase propertyBase)
=> StructuralType.CheckContains(propertyBase) is not IProperty property || !IsConceptualNull(property)
- ? ReadPropertyValue(propertyBase)
- : null;
+ ? ReadPropertyValue(propertyBase)
+ : null;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -968,7 +974,7 @@ public void SetOriginalValue(
}
}
else if (isComplexCollection
- && EntityState is EntityState.Unchanged or EntityState.Modified)
+ && EntityState is EntityState.Unchanged or EntityState.Modified)
{
((StateManager as StateManager)?.ChangeDetector as ChangeDetector)?.DetectComplexCollectionChanges(this, complexProperty!);
}
@@ -1008,7 +1014,8 @@ private void ReorderOriginalComplexCollectionEntries(IComplexProperty complexPro
for (; newOrdinal < newOriginalCollection.Count; newOrdinal++)
{
var element = newOriginalCollection[newOrdinal];
- if (element != null && elementToOriginalEntry.TryGetValue(element, out var originalEntry)
+ if (element != null
+ && elementToOriginalEntry.TryGetValue(element, out var originalEntry)
&& originalEntry.OriginalOrdinal != newOrdinal)
{
if (originalEntry.EntityState is EntityState.Detached or EntityState.Added)
@@ -1109,7 +1116,7 @@ public InternalComplexEntry GetComplexCollectionEntry(IComplexProperty property,
StructuralType.CheckContains(property);
Check.DebugAssert(property.IsCollection, $"Property {property.Name} should be a collection");
- return _complexCollectionEntries[property.GetIndex()].GetOrCreateEntries(original: false)!;
+ return _complexCollectionEntries[property.GetIndex()].GetOrCreateEntries(original: false);
}
///
@@ -1137,7 +1144,7 @@ public InternalComplexEntry GetComplexCollectionOriginalEntry(IComplexProperty p
StructuralType.CheckContains(property);
Check.DebugAssert(property.IsCollection, $"Property {property.Name} should be a collection");
- return _complexCollectionEntries[property.GetIndex()].GetOrCreateEntries(original: true)!;
+ return _complexCollectionEntries[property.GetIndex()].GetOrCreateEntries(original: true);
}
///
@@ -1155,7 +1162,11 @@ public IEnumerable GetFlattenedComplexEntries()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual void EnsureComplexCollectionEntriesCapacity(IComplexProperty property, int capacity, int originalCapacity, bool trim = true)
+ public virtual void EnsureComplexCollectionEntriesCapacity(
+ IComplexProperty property,
+ int capacity,
+ int originalCapacity,
+ bool trim = true)
{
StructuralType.CheckContains(property);
Check.DebugAssert(property.IsCollection, $"Property {property.Name} should be a collection");
@@ -1319,9 +1330,9 @@ private void SetProperty(
if (asProperty != null
&& valueType == CurrentValueType.Normal
&& (!asProperty.ClrType.IsNullableType()
- || asProperty.GetContainingForeignKeys().Any(
- fk => fk is { IsRequired: true, DeleteBehavior: DeleteBehavior.Cascade or DeleteBehavior.ClientCascade }
- && fk.DeclaringEntityType.IsAssignableFrom(StructuralType))))
+ || asProperty.GetContainingForeignKeys().Any(fk
+ => fk is { IsRequired: true, DeleteBehavior: DeleteBehavior.Cascade or DeleteBehavior.ClientCascade }
+ && fk.DeclaringEntityType.IsAssignableFrom(StructuralType))))
{
if (value == null)
{
@@ -1695,8 +1706,8 @@ public bool HasExplicitValue(IProperty property)
StructuralType.CheckContains(property);
return !HasSentinelValue(property)
- || _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsStoreGenerated)
- || _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsTemporary);
+ || _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsStoreGenerated)
+ || _stateData.IsPropertyFlagged(property.GetIndex(), PropertyFlag.IsTemporary);
}
private bool HasSentinelValue(IProperty property)
@@ -1704,8 +1715,8 @@ private bool HasSentinelValue(IProperty property)
StructuralType.CheckContains(property);
return property.IsShadowProperty()
- ? AreEqual(_shadowValues[property.GetShadowIndex()], property.Sentinel, property)
- : property.GetGetter().HasSentinelValueUsingContainingEntity(EntityEntry.Entity);
+ ? AreEqual(_shadowValues[property.GetShadowIndex()], property.Sentinel, property)
+ : property.GetGetter().HasSentinelValueUsingContainingEntity(EntityEntry.Entity);
}
///
@@ -1717,7 +1728,8 @@ private bool HasSentinelValue(IProperty property)
public bool HasStoreGeneratedValue(IProperty property)
=> GetValueType(property) == CurrentValueType.StoreGenerated;
- IInternalEntry IInternalEntry.ContainingEntry => ContainingEntry;
+ IInternalEntry IInternalEntry.ContainingEntry
+ => ContainingEntry;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs b/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
index e5e1ebac0ef..1a7342cd017 100644
--- a/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
+++ b/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
@@ -208,9 +208,8 @@ public virtual void NavigationReferenceChanged(
// Clear the inverse reference, unless it has already been changed
if (inverse != null
&& ReferenceEquals(oldTargetEntry[inverse], entry.Entity)
- && (entry.EntityType.GetNavigations().All(
- n => n == navigation
- || !ReferenceEquals(oldTargetEntry.Entity, entry[n]))))
+ && (entry.EntityType.GetNavigations().All(n => n == navigation
+ || !ReferenceEquals(oldTargetEntry.Entity, entry[n]))))
{
SetNavigation(oldTargetEntry, inverse, null, fromQuery: false);
}
@@ -1204,15 +1203,14 @@ bool TryFind(
IForeignKey secondForeignKey,
out InternalEntityEntry? joinEntry)
{
- var key = joinEntityType.FindKey(new[] { firstForeignKey.Properties[0], secondForeignKey.Properties[0] });
+ var key = joinEntityType.FindKey([firstForeignKey.Properties[0], secondForeignKey.Properties[0]]);
if (key != null)
{
joinEntry = entry.StateManager.TryGetEntry(
key,
- new[]
- {
+ [
firstEntry[firstForeignKey.PrincipalKey.Properties[0]], secondEntry[secondForeignKey.PrincipalKey.Properties[0]]
- });
+ ]);
return true;
}
diff --git a/src/EFCore/ChangeTracking/Internal/NullableValueComparer`.cs b/src/EFCore/ChangeTracking/Internal/NullableValueComparer`.cs
index eaaefe13a1a..4050d775f62 100644
--- a/src/EFCore/ChangeTracking/Internal/NullableValueComparer`.cs
+++ b/src/EFCore/ChangeTracking/Internal/NullableValueComparer`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
@@ -12,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public class NullableValueComparer
- <[DynamicallyAccessedMembers(
+<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T> : ValueComparer, IInfrastructure
diff --git a/src/EFCore/ChangeTracking/Internal/OriginalPropertyValues.cs b/src/EFCore/ChangeTracking/Internal/OriginalPropertyValues.cs
index 47793412cfd..6b4165b4ac9 100644
--- a/src/EFCore/ChangeTracking/Internal/OriginalPropertyValues.cs
+++ b/src/EFCore/ChangeTracking/Internal/OriginalPropertyValues.cs
@@ -71,7 +71,8 @@ protected override void SetValueInternal(IInternalEntry entry, IPropertyBase pro
// The stored original collection might contain references to the current elements,
// so we need to recreate it using stored values.
- var clonedCollection = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor().Create(originalCollection.Count);
+ var clonedCollection = (IList)((IRuntimePropertyBase)complexProperty).GetIndexedCollectionAccessor()
+ .Create(originalCollection.Count);
for (var i = 0; i < originalCollection.Count; i++)
{
clonedCollection.Add(
diff --git a/src/EFCore/ChangeTracking/Internal/SimpleFullyNullableDependentKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/SimpleFullyNullableDependentKeyValueFactory.cs
index ebb618df0c6..ac83bf4545c 100644
--- a/src/EFCore/ChangeTracking/Internal/SimpleFullyNullableDependentKeyValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/SimpleFullyNullableDependentKeyValueFactory.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
diff --git a/src/EFCore/ChangeTracking/Internal/SimpleNonNullableDependentKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/SimpleNonNullableDependentKeyValueFactory.cs
index 472c5283e04..c45d4865c80 100644
--- a/src/EFCore/ChangeTracking/Internal/SimpleNonNullableDependentKeyValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/SimpleNonNullableDependentKeyValueFactory.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
diff --git a/src/EFCore/ChangeTracking/Internal/SimpleNullablePrincipalDependentKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/SimpleNullablePrincipalDependentKeyValueFactory.cs
index 67942dc3ad1..2e4c114edf3 100644
--- a/src/EFCore/ChangeTracking/Internal/SimpleNullablePrincipalDependentKeyValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/SimpleNullablePrincipalDependentKeyValueFactory.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
diff --git a/src/EFCore/ChangeTracking/Internal/SimplePrincipalKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/SimplePrincipalKeyValueFactory.cs
index 1757474eb0c..f39e2d5747a 100644
--- a/src/EFCore/ChangeTracking/Internal/SimplePrincipalKeyValueFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/SimplePrincipalKeyValueFactory.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
diff --git a/src/EFCore/ChangeTracking/Internal/Snapshot.cs b/src/EFCore/ChangeTracking/Internal/Snapshot.cs
index 460dfc5c6e0..7b2fc0ae283 100644
--- a/src/EFCore/ChangeTracking/Internal/Snapshot.cs
+++ b/src/EFCore/ChangeTracking/Internal/Snapshot.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
diff --git a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs
index f4bb13c6d81..28d31f20e7e 100644
--- a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs
@@ -57,7 +57,9 @@ public virtual Expression CreateConstructorExpression(
var index = GetPropertyIndex(propertyBase);
if (index >= 0)
{
- Check.DebugAssert(propertyBases[index] == null, $"Both {propertyBase.Name} and {propertyBases[index]?.Name} have the same index {index}.");
+ Check.DebugAssert(
+ propertyBases[index] == null,
+ $"Both {propertyBase.Name} and {propertyBases[index]?.Name} have the same index {index}.");
types[index] = (propertyBase as IProperty)?.ClrType ?? typeof(object);
propertyBases[index] = propertyBase;
@@ -65,7 +67,8 @@ public virtual Expression CreateConstructorExpression(
}
}
- Check.DebugAssert(actualCount == count,
+ Check.DebugAssert(
+ actualCount == count,
$"Count of snapshottable properties {actualCount} for {structuralType.DisplayName()} does not match expected count {count}.");
Expression constructorExpression;
@@ -117,7 +120,8 @@ protected virtual Expression CreateSnapshotExpression(
? null
: Expression.Variable(clrType, "structuralType");
- Check.DebugAssert(structuralTypeVariable != null || count == 0,
+ Check.DebugAssert(
+ structuralTypeVariable != null || count == 0,
"If there are any properties then the entity parameter must be used");
var indicesExpression = parameter == null || !parameter.Type.IsAssignableTo(typeof(IInternalEntry))
? (Expression)Expression.Property(null, typeof(ReadOnlySpan), nameof(ReadOnlySpan<>.Empty))
@@ -204,7 +208,6 @@ private Expression CreateSnapshotValueExpression(Expression expression, IPropert
? Expression.Call(
null,
SnapshotComplexCollectionMethod,
-
expression.Type.IsAssignableTo(typeof(IList))
? expression
: Expression.Convert(expression, typeof(IList)),
@@ -216,10 +219,11 @@ private Expression CreateSnapshotValueExpression(Expression expression, IPropert
? expression
: Expression.Convert(expression, typeof(IEnumerable)));
}
+
return expression;
}
- if (GetValueComparer(property) is not ValueComparer comparer)
+ if (GetValueComparer(property) is not { } comparer)
{
return expression;
}
@@ -339,11 +343,13 @@ private static readonly MethodInfo SnapshotCollectionMethod
{
return null;
}
+
var snapshot = new HashSet(ReferenceEqualityComparer.Instance);
foreach (var item in collection)
{
snapshot.Add(item);
}
+
return snapshot;
}
@@ -369,6 +375,7 @@ private static readonly MethodInfo SnapshotComplexCollectionMethod
// We need to preserve the original reference, these are only used to find moved items, not modified properties on them
snapshot.Add(item);
}
+
return snapshot;
}
}
diff --git a/src/EFCore/ChangeTracking/Internal/StateManager.cs b/src/EFCore/ChangeTracking/Internal/StateManager.cs
index 5527fc6e1e0..51ca099f032 100644
--- a/src/EFCore/ChangeTracking/Internal/StateManager.cs
+++ b/src/EFCore/ChangeTracking/Internal/StateManager.cs
@@ -935,7 +935,7 @@ public virtual IEnumerable> GetRecor
return danglers;
}
- return Enumerable.Empty>();
+ return [];
}
///
@@ -1042,7 +1042,7 @@ public virtual IEnumerable GetDependents(
var dependentIdentityMap = FindIdentityMap(foreignKey.DeclaringEntityType.FindPrimaryKey());
return dependentIdentityMap != null && foreignKey.PrincipalEntityType.IsAssignableFrom(principalEntry.EntityType)
? dependentIdentityMap.GetDependentsMap(foreignKey).GetDependents(principalEntry)
- : Enumerable.Empty();
+ : [];
}
///
@@ -1055,7 +1055,7 @@ public virtual IEnumerable GetEntries(IKey key)
{
var identityMap = FindIdentityMap(key);
return identityMap == null
- ? Enumerable.Empty()
+ ? []
: identityMap.All();
}
@@ -1087,7 +1087,7 @@ public virtual IEnumerable GetDependentsUsingRelationshipSnapshot(
var dependentIdentityMap = FindIdentityMap(foreignKey.DeclaringEntityType.FindPrimaryKey());
return dependentIdentityMap != null
? dependentIdentityMap.GetDependentsMap(foreignKey).GetDependentsUsingRelationshipSnapshot(principalEntry)
- : Enumerable.Empty();
+ : [];
}
///
@@ -1110,7 +1110,7 @@ public virtual IEnumerable GetDependentsUsingRelationshipSnapshot(
var navigationValue = ((InternalEntityEntry)principalEntry)[navigation];
if (navigationValue == null)
{
- return Enumerable.Empty();
+ return [];
}
if (foreignKey.IsUnique)
diff --git a/src/EFCore/ChangeTracking/Internal/TemporaryValuesFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/TemporaryValuesFactoryFactory.cs
index 459a815fc28..c9204c2d8e8 100644
--- a/src/EFCore/ChangeTracking/Internal/TemporaryValuesFactoryFactory.cs
+++ b/src/EFCore/ChangeTracking/Internal/TemporaryValuesFactoryFactory.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
///
diff --git a/src/EFCore/ChangeTracking/ListOfReferenceTypesComparer.cs b/src/EFCore/ChangeTracking/ListOfReferenceTypesComparer.cs
index 5bf444702eb..33da583f6bc 100644
--- a/src/EFCore/ChangeTracking/ListOfReferenceTypesComparer.cs
+++ b/src/EFCore/ChangeTracking/ListOfReferenceTypesComparer.cs
@@ -30,7 +30,8 @@ public sealed class ListOfReferenceTypesComparer : Valu
&& typeof(TConcreteList).GetGenericTypeDefinition() == typeof(ReadOnlyCollection<>));
private static readonly MethodInfo CompareMethod = typeof(ListOfReferenceTypesComparer).GetMethod(
- nameof(Compare), BindingFlags.Static | BindingFlags.NonPublic, [typeof(object), typeof(object), typeof(Func)])!;
+ nameof(Compare), BindingFlags.Static | BindingFlags.NonPublic,
+ [typeof(object), typeof(object), typeof(Func)])!;
private static readonly MethodInfo GetHashCodeMethod = typeof(ListOfReferenceTypesComparer).GetMethod(
nameof(GetHashCode), BindingFlags.Static | BindingFlags.NonPublic, [typeof(IEnumerable), typeof(Func)])!;
diff --git a/src/EFCore/ChangeTracking/LocalView.cs b/src/EFCore/ChangeTracking/LocalView.cs
index 661c0ccd06d..24e6d6691d5 100644
--- a/src/EFCore/ChangeTracking/LocalView.cs
+++ b/src/EFCore/ChangeTracking/LocalView.cs
@@ -5,7 +5,6 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Internal;
@@ -61,7 +60,6 @@ public class LocalView<[DynamicallyAccessedMembers(IEntityType.DynamicallyAccess
private readonly DbContext _context;
private readonly IEntityType _entityType;
private int _countChanges;
- private IEntityFinder? _finder;
private int? _count;
private bool _triggeringStateManagerChange;
private bool _triggeringObservableChange;
@@ -176,7 +174,7 @@ private void ObservableCollectionChanged(object? _, NotifyCollectionChangedEvent
}
///
- /// Returns an for all tracked entities of type
+ /// Returns an for all tracked entities of type
/// that are not marked as deleted.
///
/// An enumerator for the collection.
@@ -184,7 +182,7 @@ public virtual IEnumerator GetEnumerator()
=> _context.GetDependencies().StateManager.GetNonDeletedEntities().GetEnumerator();
///
- /// Returns an for all tracked entities of type
+ /// Returns an for all tracked entities of type
/// that are not marked as deleted.
///
/// An enumerator for the collection.
@@ -237,7 +235,7 @@ public virtual void Add(TEntity item)
}
///
- /// Marks all entities of type being tracked by the
+ /// Marks all entities of type being tracked by the
/// as .
///
///
@@ -280,7 +278,7 @@ public virtual bool Contains(TEntity item)
}
///
- /// Copies to an array all entities of type that are being tracked and are
+ /// Copies to an array all entities of type that are being tracked and are
/// not marked as Deleted.
///
///
@@ -382,7 +380,7 @@ private void StateManagerChangedHandler(InternalEntityEntry entry, EntityState p
}
///
- /// The number of entities of type that are being tracked and are not marked
+ /// The number of entities of type that are being tracked and are not marked
/// as Deleted.
///
///
@@ -856,6 +854,7 @@ private IProperty FindAndValidateProperty(string propertyName)
return property;
}
+ [field: AllowNull, MaybeNull]
private IEntityFinder Finder
- => _finder ??= (IEntityFinder)_context.GetDependencies().EntityFinderFactory.Create(_entityType);
+ => field ??= (IEntityFinder)_context.GetDependencies().EntityFinderFactory.Create(_entityType);
}
diff --git a/src/EFCore/ChangeTracking/NavigationEntry.cs b/src/EFCore/ChangeTracking/NavigationEntry.cs
index fc849fac92a..46fb8ef8e46 100644
--- a/src/EFCore/ChangeTracking/NavigationEntry.cs
+++ b/src/EFCore/ChangeTracking/NavigationEntry.cs
@@ -69,7 +69,8 @@ protected NavigationEntry(InternalEntityEntry internalEntry, INavigationBase nav
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
[EntityFrameworkInternal]
- protected virtual InternalEntityEntry InternalEntityEntry => (InternalEntityEntry)InternalEntry;
+ protected virtual InternalEntityEntry InternalEntityEntry
+ => (InternalEntityEntry)InternalEntry;
private static INavigationBase GetNavigation(InternalEntityEntry internalEntry, string name)
{
diff --git a/src/EFCore/ChangeTracking/PropertyValues.cs b/src/EFCore/ChangeTracking/PropertyValues.cs
index 15480976553..79a53634f9c 100644
--- a/src/EFCore/ChangeTracking/PropertyValues.cs
+++ b/src/EFCore/ChangeTracking/PropertyValues.cs
@@ -26,7 +26,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
///
public abstract class PropertyValues
{
- private IReadOnlyList? _complexCollectionProperties;
+ private readonly IReadOnlyList _complexCollectionProperties;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -36,7 +36,13 @@ public abstract class PropertyValues
///
[EntityFrameworkInternal]
protected PropertyValues(InternalEntryBase internalEntry)
- => InternalEntry = internalEntry;
+ {
+ InternalEntry = internalEntry;
+ _complexCollectionProperties = [.. internalEntry.StructuralType.GetFlattenedComplexProperties().Where(p => p.IsCollection)];
+ Check.DebugAssert(
+ _complexCollectionProperties.Select((p, i) => p.GetIndex() == i).All(e => e),
+ "Complex collection properties indices are not sequential.");
+ }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -145,17 +151,7 @@ public virtual IReadOnlyList Properties
public virtual IReadOnlyList ComplexCollectionProperties
{
[DebuggerStepThrough]
- get
- {
- if (_complexCollectionProperties == null)
- {
- _complexCollectionProperties = [.. StructuralType.GetFlattenedComplexProperties().Where(p => p.IsCollection)];
- Check.DebugAssert(
- _complexCollectionProperties.Select((p, i) => p.GetIndex() == i).All(e => e),
- "Complex collection properties indices are not sequential.");
- }
- return _complexCollectionProperties;
- }
+ get => _complexCollectionProperties;
}
///
diff --git a/src/EFCore/ChangeTracking/ReferenceEntry.cs b/src/EFCore/ChangeTracking/ReferenceEntry.cs
index 276628ed3b5..06f1886fc1d 100644
--- a/src/EFCore/ChangeTracking/ReferenceEntry.cs
+++ b/src/EFCore/ChangeTracking/ReferenceEntry.cs
@@ -23,8 +23,6 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
///
public class ReferenceEntry : NavigationEntry
{
- private IEntityFinder? _finder;
-
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -270,6 +268,7 @@ public virtual EntityEntry? TargetEntry
? null
: InternalEntry.StateManager.GetOrCreateEntry(CurrentValue, Metadata.TargetEntityType);
+ [field: AllowNull, MaybeNull]
private IEntityFinder TargetFinder
- => _finder ??= InternalEntry.StateManager.CreateEntityFinder(Metadata.TargetEntityType);
+ => field ??= InternalEntry.StateManager.CreateEntityFinder(Metadata.TargetEntityType);
}
diff --git a/src/EFCore/ChangeTracking/ValueComparer.cs b/src/EFCore/ChangeTracking/ValueComparer.cs
index 34696dbd2bc..06423fbf54f 100644
--- a/src/EFCore/ChangeTracking/ValueComparer.cs
+++ b/src/EFCore/ChangeTracking/ValueComparer.cs
@@ -3,7 +3,6 @@
using System.Collections;
using System.Collections.Concurrent;
-using System.Diagnostics.CodeAnalysis;
namespace Microsoft.EntityFrameworkCore.ChangeTracking;
@@ -41,7 +40,10 @@ internal static readonly MethodInfo EqualityComparerEqualsMethod
internal static readonly MethodInfo ObjectGetHashCodeMethod
= typeof(object).GetRuntimeMethod(nameof(object.GetHashCode), Type.EmptyTypes)!;
- private static readonly ConcurrentDictionary _genericSnapshotMethodMap = new();
+ internal static readonly PropertyInfo StructuralComparisonsStructuralEqualityComparerProperty =
+ typeof(StructuralComparisons).GetProperty(nameof(StructuralComparisons.StructuralEqualityComparer))!;
+
+ private static readonly ConcurrentDictionary GenericSnapshotMethodMap = new();
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -51,13 +53,13 @@ internal static readonly MethodInfo ObjectGetHashCodeMethod
///
[EntityFrameworkInternal]
public static MethodInfo GetGenericSnapshotMethod(Type type)
- => _genericSnapshotMethodMap.GetOrAdd(
+ => GenericSnapshotMethodMap.GetOrAdd(
type, t =>
typeof(ValueComparer<>).MakeGenericType(t).GetGenericMethod(
- nameof(ValueComparer.Snapshot),
+ nameof(ValueComparer<>.Snapshot),
genericParameterCount: 0,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
- (a, b) => new[] { a[0] },
+ (a, b) => [a[0]],
@override: false)!);
///
@@ -78,7 +80,7 @@ protected static readonly MethodInfo HashCodeAddMethod
///
[EntityFrameworkInternal]
protected static readonly MethodInfo ToHashCodeMethod
- = typeof(HashCode).GetRuntimeMethod(nameof(HashCode.ToHashCode), new Type[0])!;
+ = typeof(HashCode).GetRuntimeMethod(nameof(HashCode.ToHashCode), [])!;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -195,7 +197,7 @@ public virtual Expression ExtractEqualsBody(
var original2 = EqualsExpression.Parameters[1];
return new ReplacingExpressionVisitor(
- new Expression[] { original1, original2 }, new[] { leftExpression, rightExpression })
+ [original1, original2], [leftExpression, rightExpression])
.Visit(EqualsExpression.Body);
}
@@ -279,7 +281,7 @@ public static ValueComparer CreateDefault(
/// The type.
/// The .
public static ValueComparer CreateDefault
- <[DynamicallyAccessedMembers(
+ <[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T>(bool favorStructuralComparisons)
@@ -317,7 +319,7 @@ public static ValueComparer CreateDefault
// PublicMethods is required to preserve e.g. GetHashCode
internal class DefaultValueComparer
- <[DynamicallyAccessedMembers(
+ <[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T> : ValueComparer
diff --git a/src/EFCore/ChangeTracking/ValueComparer`.cs b/src/EFCore/ChangeTracking/ValueComparer`.cs
index 13d56a1b8e3..7631f074234 100644
--- a/src/EFCore/ChangeTracking/ValueComparer`.cs
+++ b/src/EFCore/ChangeTracking/ValueComparer`.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Internal;
using ExpressionExtensions = Microsoft.EntityFrameworkCore.Infrastructure.ExpressionExtensions;
using static System.Linq.Expressions.Expression;
@@ -29,7 +28,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
/// The type.
// PublicMethods is required to preserve e.g. GetHashCode
public class ValueComparer
- <[DynamicallyAccessedMembers(
+<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T> : ValueComparer, IEqualityComparer
@@ -37,10 +36,6 @@ public class ValueComparer
private Func? _equals;
private Func? _hashCode;
private Func? _snapshot;
- private LambdaExpression? _objectEqualsExpression;
-
- private static readonly PropertyInfo StructuralComparisonsStructuralEqualityComparerProperty =
- typeof(StructuralComparisons).GetProperty(nameof(StructuralComparisons.StructuralEqualityComparer))!;
///
/// Creates a new with a default comparison
@@ -129,12 +124,11 @@ public ValueComparer(
param1, param2);
}
- var typedEquals = type.GetRuntimeMethods().FirstOrDefault(
- m => m.ReturnType == typeof(bool)
- && !m.IsStatic
- && nameof(object.Equals).Equals(m.Name, StringComparison.Ordinal)
- && m.GetParameters().Length == 1
- && m.GetParameters()[0].ParameterType == typeof(T));
+ var typedEquals = type.GetRuntimeMethods().FirstOrDefault(m => m.ReturnType == typeof(bool)
+ && !m.IsStatic
+ && nameof(object.Equals).Equals(m.Name, StringComparison.Ordinal)
+ && m.GetParameters().Length == 1
+ && m.GetParameters()[0].ParameterType == typeof(T));
if (typedEquals != null)
{
@@ -157,13 +151,12 @@ public ValueComparer(
&& type != null)
{
var declaredMethods = type.GetTypeInfo().DeclaredMethods;
- typedEquals = declaredMethods.FirstOrDefault(
- m => m.IsStatic
- && m.ReturnType == typeof(bool)
- && "op_Equality".Equals(m.Name, StringComparison.Ordinal)
- && m.GetParameters().Length == 2
- && m.GetParameters()[0].ParameterType == typeof(T)
- && m.GetParameters()[1].ParameterType == typeof(T));
+ typedEquals = declaredMethods.FirstOrDefault(m => m.IsStatic
+ && m.ReturnType == typeof(bool)
+ && "op_Equality".Equals(m.Name, StringComparison.Ordinal)
+ && m.GetParameters().Length == 2
+ && m.GetParameters()[0].ParameterType == typeof(T)
+ && m.GetParameters()[1].ParameterType == typeof(T));
type = type.BaseType;
}
@@ -252,11 +245,12 @@ public override bool Equals(object? left, object? right)
}
///
+ [field: AllowNull, MaybeNull]
public override LambdaExpression ObjectEqualsExpression
{
get
{
- if (_objectEqualsExpression == null)
+ if (field == null)
{
var left = Parameter(typeof(object), "left");
var right = Parameter(typeof(object), "right");
@@ -266,7 +260,7 @@ public override LambdaExpression ObjectEqualsExpression
[Convert(left, typeof(T)), Convert(right, typeof(T))],
EqualsExpression.Body);
- _objectEqualsExpression = Lambda>(
+ field = Lambda>(
Condition(
Equal(left, Constant(null)),
Equal(right, Constant(null)),
@@ -277,7 +271,7 @@ public override LambdaExpression ObjectEqualsExpression
right);
}
- return _objectEqualsExpression;
+ return field;
}
}
diff --git a/src/EFCore/DbContext.cs b/src/EFCore/DbContext.cs
index 4e5ce4e2d39..e2464d9da1b 100644
--- a/src/EFCore/DbContext.cs
+++ b/src/EFCore/DbContext.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Internal;
@@ -80,11 +79,10 @@ public class DbContext :
/// for more information and examples.
///
[RequiresUnreferencedCode(
- "EF Core isn't fully compatible with trimming, and running the application may generate unexpected runtime failures. "
- + "Some specific coding pattern are usually required to make trimming work properly, see https://aka.ms/efcore-docs-trimming for "
- + "more details.")]
- [RequiresDynamicCode(
- "EF Core isn't fully compatible with NativeAOT, and running the application may generate unexpected runtime failures.")]
+ "EF Core isn't fully compatible with trimming, and running the application may generate unexpected runtime failures. "
+ + "Some specific coding pattern are usually required to make trimming work properly, see https://aka.ms/efcore-docs-trimming for "
+ + "more details."), RequiresDynamicCode(
+ "EF Core isn't fully compatible with NativeAOT, and running the application may generate unexpected runtime failures.")]
protected DbContext()
: this(new DbContextOptions())
{
@@ -101,11 +99,10 @@ protected DbContext()
///
/// The options for this context.
[RequiresUnreferencedCode(
- "EF Core isn't fully compatible with trimming, and running the application may generate unexpected runtime failures. "
- + "Some specific coding pattern are usually required to make trimming work properly, see https://aka.ms/efcore-docs-trimming for "
- + "more details.")]
- [RequiresDynamicCode(
- "EF Core isn't fully compatible with NativeAOT, and running the application may generate unexpected runtime failures.")]
+ "EF Core isn't fully compatible with trimming, and running the application may generate unexpected runtime failures. "
+ + "Some specific coding pattern are usually required to make trimming work properly, see https://aka.ms/efcore-docs-trimming for "
+ + "more details."), RequiresDynamicCode(
+ "EF Core isn't fully compatible with NativeAOT, and running the application may generate unexpected runtime failures.")]
public DbContext(DbContextOptions options)
{
Check.NotNull(options);
diff --git a/src/EFCore/DbContextOptions.cs b/src/EFCore/DbContextOptions.cs
index 13839281a16..90b347ef80d 100644
--- a/src/EFCore/DbContextOptions.cs
+++ b/src/EFCore/DbContextOptions.cs
@@ -136,9 +136,8 @@ public override bool Equals(object? obj)
protected virtual bool Equals(DbContextOptions other)
=> _extensionsMap.Count == other._extensionsMap.Count
&& _extensionsMap.Zip(other._extensionsMap)
- .All(
- p => p.First.Value.Ordinal == p.Second.Value.Ordinal
- && p.First.Value.Extension.Info.ShouldUseSameServiceProvider(p.Second.Value.Extension.Info));
+ .All(p => p.First.Value.Ordinal == p.Second.Value.Ordinal
+ && p.First.Value.Extension.Info.ShouldUseSameServiceProvider(p.Second.Value.Extension.Info));
///
public override int GetHashCode()
diff --git a/src/EFCore/DbSet.cs b/src/EFCore/DbSet.cs
index 10f4dcc0e1f..7a89377df71 100644
--- a/src/EFCore/DbSet.cs
+++ b/src/EFCore/DbSet.cs
@@ -3,7 +3,6 @@
using System.Collections;
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
namespace Microsoft.EntityFrameworkCore;
diff --git a/src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs b/src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs
index ee574cc4aaa..89c3546a52b 100644
--- a/src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs
+++ b/src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs
@@ -374,7 +374,7 @@ public static void Create(
{
var mainBuilder = parameters.MainBuilder;
var constructor = converter.GetType().GetDeclaredConstructor([typeof(JsonValueReaderWriter)]);
- var jsonReaderWriterProperty = converter.GetType().GetProperty(nameof(CollectionToJsonStringConverter.JsonReaderWriter));
+ var jsonReaderWriterProperty = converter.GetType().GetProperty(nameof(CollectionToJsonStringConverter<>.JsonReaderWriter));
if (constructor == null
|| jsonReaderWriterProperty == null)
{
@@ -455,7 +455,7 @@ public static void Create(
.Any(t => t == typeof(ValueComparer) || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ValueComparer<>)));
if (!containsNestedComparerCtor
- || comparer is not IInfrastructure { Instance: ValueComparer underlyingValueComparer })
+ || comparer is not IInfrastructure { Instance: { } underlyingValueComparer })
{
AddNamespace(typeof(ValueComparer<>), parameters.Namespaces);
AddNamespace(comparer.Type, parameters.Namespaces);
diff --git a/src/EFCore/Design/MethodCallCodeFragment.cs b/src/EFCore/Design/MethodCallCodeFragment.cs
index 97a9fc8f615..c8e68ae3e0a 100644
--- a/src/EFCore/Design/MethodCallCodeFragment.cs
+++ b/src/EFCore/Design/MethodCallCodeFragment.cs
@@ -98,7 +98,7 @@ private MethodCallCodeFragment(
public virtual string Method { get; }
IEnumerable IMethodCallCodeFragment.TypeArguments
- => Enumerable.Empty();
+ => [];
///
/// Gets the method call's arguments.
diff --git a/src/EFCore/Diagnostics/ConcurrencyExceptionEventData.cs b/src/EFCore/Diagnostics/ConcurrencyExceptionEventData.cs
index ca051e929e4..d4feb4f2266 100644
--- a/src/EFCore/Diagnostics/ConcurrencyExceptionEventData.cs
+++ b/src/EFCore/Diagnostics/ConcurrencyExceptionEventData.cs
@@ -14,7 +14,6 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics;
public class ConcurrencyExceptionEventData : DbContextErrorEventData
{
private readonly IReadOnlyList _internalEntries;
- private IReadOnlyList? _entries;
///
/// Constructs the event payload.
@@ -42,6 +41,7 @@ public ConcurrencyExceptionEventData(
///
/// The entries that were involved in the concurrency violation.
///
+ [field: AllowNull, MaybeNull]
public virtual IReadOnlyList Entries
- => _entries ??= _internalEntries.Select(e => new EntityEntry((InternalEntityEntry)e)).ToList();
+ => field ??= _internalEntries.Select(e => new EntityEntry((InternalEntityEntry)e)).ToList();
}
diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs
index 9fb70ad7d5d..5054434a5ba 100644
--- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs
+++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs
@@ -1603,9 +1603,9 @@ private static string AccidentalComplexPropertyCollection(EventDefinitionBase de
var d = (EventDefinition)definition;
var p = (ComplexPropertyEventData)payload;
return d.GenerateMessage(
- p.Property.DeclaringType.DisplayName(),
- p.Property.Name,
- p.Property.ClrType.ShortDisplayName());
+ p.Property.DeclaringType.DisplayName(),
+ p.Property.Name,
+ p.Property.ClrType.ShortDisplayName());
}
///
@@ -1784,8 +1784,8 @@ public static void MultiplePrimaryKeyCandidates(
var eventData = new TwoPropertyBaseCollectionsEventData(
definition,
MultiplePrimaryKeyCandidates,
- new[] { firstProperty },
- new[] { secondProperty });
+ [firstProperty],
+ [secondProperty]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -1816,6 +1816,7 @@ public static void MultipleNavigationProperties(
{
var definition = CoreResources.LogMultipleNavigationProperties(diagnostics);
+ // ReSharper disable PossibleMultipleEnumeration
if (diagnostics.ShouldLog(definition))
{
definition.Log(
@@ -1836,6 +1837,7 @@ public static void MultipleNavigationProperties(
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
+ // ReSharper restore PossibleMultipleEnumeration
}
private static string MultipleNavigationProperties(EventDefinitionBase definition, EventData payload)
@@ -1878,7 +1880,7 @@ public static void MultipleInversePropertiesSameTargetWarning(
definition,
MultipleInversePropertiesSameTargetWarning,
conflictingNavigations,
- new[] { new Tuple(inverseNavigation, targetType) });
+ [new Tuple(inverseNavigation, targetType)]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -1929,12 +1931,11 @@ public static void NonOwnershipInverseNavigationWarning(
var eventData = new TwoUnmappedPropertyCollectionsEventData(
definition,
NonOwnershipInverseNavigationWarning,
- new[] { new Tuple(navigation, declaringType.ClrType) },
- new[]
- {
+ [new Tuple(navigation, declaringType.ClrType)],
+ [
new Tuple(inverseNavigation, targetType.ClrType),
new Tuple(ownershipNavigation, targetType.ClrType)
- });
+ ]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -1989,18 +1990,16 @@ public static void ForeignKeyAttributesOnBothPropertiesWarning(
var eventData = new TwoUnmappedPropertyCollectionsEventData(
definition,
ForeignKeyAttributesOnBothPropertiesWarning,
- new[]
- {
+ [
new Tuple(
firstNavigation.GetIdentifyingMemberInfo()!, firstNavigation.DeclaringEntityType.ClrType),
new Tuple(firstProperty, firstNavigation.DeclaringEntityType.ClrType)
- },
- new[]
- {
+ ],
+ [
new Tuple(
secondNavigation.GetIdentifyingMemberInfo()!, secondNavigation.DeclaringEntityType.ClrType),
new Tuple(secondProperty, secondNavigation.DeclaringEntityType.ClrType)
- });
+ ]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -2051,8 +2050,8 @@ public static void ForeignKeyAttributesOnBothNavigationsWarning(
var eventData = new TwoPropertyBaseCollectionsEventData(
definition,
ForeignKeyAttributesOnBothNavigationsWarning,
- new[] { firstNavigation },
- new[] { secondNavigation });
+ [firstNavigation],
+ [secondNavigation]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -2099,8 +2098,8 @@ public static void ConflictingForeignKeyAttributesOnNavigationAndPropertyWarning
var eventData = new TwoUnmappedPropertyCollectionsEventData(
definition,
ConflictingForeignKeyAttributesOnNavigationAndPropertyWarning,
- new[] { new Tuple(navigation.GetIdentifyingMemberInfo()!, navigation.DeclaringEntityType.ClrType) },
- new[] { new Tuple(property, property.DeclaringType!) });
+ [new Tuple(navigation.GetIdentifyingMemberInfo()!, navigation.DeclaringEntityType.ClrType)],
+ [new Tuple(property, property.DeclaringType!)]);
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
@@ -2359,7 +2358,8 @@ public static void ComplexElementPropertyChangeDetectedSensitive(
property.Name,
oldValue,
newValue,
- internalComplexEntry.EntityEntry.BuildCurrentValuesString(property.DeclaringType.ContainingEntityType.FindPrimaryKey()!.Properties));
+ internalComplexEntry.EntityEntry.BuildCurrentValuesString(
+ property.DeclaringType.ContainingEntityType.FindPrimaryKey()!.Properties));
}
if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
@@ -3071,7 +3071,7 @@ private static string ValueGenerated(EventDefinitionBase definition, EventData p
/// The internal entity entry.
/// The property.
/// The value generated.
- /// Indicates whether or not the value is a temporary or permanent value.
+ /// Indicates whether the value is a temporary or permanent value.
public static void ValueGeneratedSensitive(
this IDiagnosticsLogger diagnostics,
InternalEntityEntry internalEntityEntry,
diff --git a/src/EFCore/Diagnostics/EventDefinitionBase.cs b/src/EFCore/Diagnostics/EventDefinitionBase.cs
index f3d9f50f17f..d1d2bdb466b 100644
--- a/src/EFCore/Diagnostics/EventDefinitionBase.cs
+++ b/src/EFCore/Diagnostics/EventDefinitionBase.cs
@@ -31,7 +31,6 @@ protected EventDefinitionBase(
EventIdCode = eventIdCode;
var warningsConfiguration = loggingOptions.WarningsConfiguration;
-
if (warningsConfiguration != null)
{
var levelOverride = warningsConfiguration.GetLevel(eventId);
@@ -86,12 +85,11 @@ protected virtual Exception WarningAsError(string message)
internal sealed class MessageExtractingLogger : ILogger
{
- private string? _message;
-
+ [field: AllowNull, MaybeNull]
public string Message
{
- get => _message ?? throw new InvalidOperationException();
- private set => _message = value;
+ get => field ?? throw new InvalidOperationException();
+ private set;
}
void ILogger.Log(
diff --git a/src/EFCore/Diagnostics/IdentityResolutionInterceptionData.cs b/src/EFCore/Diagnostics/IdentityResolutionInterceptionData.cs
index e8d363fcea2..b0c22a35178 100644
--- a/src/EFCore/Diagnostics/IdentityResolutionInterceptionData.cs
+++ b/src/EFCore/Diagnostics/IdentityResolutionInterceptionData.cs
@@ -17,8 +17,7 @@ public readonly struct IdentityResolutionInterceptionData
/// Constructs the parameter object.
///
/// The in use.
- [EntityFrameworkInternal]
- [UsedImplicitly]
+ [EntityFrameworkInternal, UsedImplicitly]
public IdentityResolutionInterceptionData(DbContext context)
=> Context = context;
diff --git a/src/EFCore/Diagnostics/InstantiationBindingInterceptionData.cs b/src/EFCore/Diagnostics/InstantiationBindingInterceptionData.cs
index 19800577210..2a9044badcc 100644
--- a/src/EFCore/Diagnostics/InstantiationBindingInterceptionData.cs
+++ b/src/EFCore/Diagnostics/InstantiationBindingInterceptionData.cs
@@ -17,8 +17,7 @@ public readonly struct InstantiationBindingInterceptionData
/// Constructs the parameter object.
///
/// The entity type for which the binding is being used.
- [EntityFrameworkInternal]
- [UsedImplicitly]
+ [EntityFrameworkInternal, UsedImplicitly]
public InstantiationBindingInterceptionData(ITypeBase typeBase)
=> TypeBase = typeBase;
diff --git a/src/EFCore/Diagnostics/InterceptionResult`.cs b/src/EFCore/Diagnostics/InterceptionResult`.cs
index 21eef6a7694..a404dd317ba 100644
--- a/src/EFCore/Diagnostics/InterceptionResult`.cs
+++ b/src/EFCore/Diagnostics/InterceptionResult`.cs
@@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics;
///
/// A value of this type is passed to all interceptor methods that are called before the operation
/// being intercepted is executed.
-/// Typically the interceptor should return the value passed in.
+/// Typically, the interceptor should return the value passed in.
/// However, creating a result with causes the operation being
/// intercepted to be suppressed; that is, the operation is not executed.
/// The value in the result is then used as a substitute return value for the operation that was suppressed.
@@ -23,8 +23,6 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics;
/// The new result to use.
public readonly struct InterceptionResult
{
- private readonly TResult _result;
-
///
/// Creates a new instance indicating that
/// execution should be suppressed and the given result should be used instead.
@@ -35,7 +33,7 @@ public static InterceptionResult SuppressWithResult(TResult result)
private InterceptionResult(TResult result)
{
- _result = result;
+ Result = result;
HasResult = true;
}
@@ -56,7 +54,7 @@ public TResult Result
throw new InvalidOperationException(CoreStrings.NoInterceptionResult);
}
- return _result;
+ return field;
}
}
diff --git a/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs b/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs
index babebe150d7..c4b59bea939 100644
--- a/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs
+++ b/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs
@@ -121,7 +121,7 @@ protected void DispatchEventData(
=> ((IDiagnosticsLogger)this).DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
///
- /// Checks whether or not the message should be sent to the .
+ /// Checks whether the message should be sent to the .
///
/// The definition of the event to log.
///
@@ -133,7 +133,7 @@ protected bool ShouldLog(EventDefinitionBase definition)
=> ((IDiagnosticsLogger)this).ShouldLog(definition);
///
- /// Determines whether or not an instance is needed based on whether or
+ /// Determines whether an instance is needed based on whether or
/// not there is a , an , or an enabled for
/// the given event.
///
diff --git a/src/EFCore/Diagnostics/Internal/Interceptors.cs b/src/EFCore/Diagnostics/Internal/Interceptors.cs
index 9047238e651..bfdef244fe6 100644
--- a/src/EFCore/Diagnostics/Internal/Interceptors.cs
+++ b/src/EFCore/Diagnostics/Internal/Interceptors.cs
@@ -14,7 +14,6 @@ public class Interceptors : IInterceptors
private readonly IServiceProvider _serviceProvider;
private readonly IEnumerable _injectedInterceptors;
private readonly Dictionary _aggregators;
- private CoreOptionsExtension? _coreOptionsExtension;
private List? _interceptors;
///
@@ -70,7 +69,7 @@ private IReadOnlyList RegisteredInterceptors
/// else is ready for them to do interception anyway.
///
private CoreOptionsExtension? CoreOptionsExtension
- => _coreOptionsExtension ??= _serviceProvider
+ => field ??= _serviceProvider
.GetRequiredService()
.Extensions
.OfType()
diff --git a/src/EFCore/Diagnostics/Internal/LoggingOptions.cs b/src/EFCore/Diagnostics/Internal/LoggingOptions.cs
index 1ce5f190765..4df4a7c46fe 100644
--- a/src/EFCore/Diagnostics/Internal/LoggingOptions.cs
+++ b/src/EFCore/Diagnostics/Internal/LoggingOptions.cs
@@ -105,13 +105,5 @@ public virtual void Validate(IDbContextOptions options)
///
public virtual bool ShouldWarnForStringEnumValueInJson(Type enumType)
- {
- if (_warnedForStringEnums.ContainsKey(enumType))
- {
- return false;
- }
-
- _warnedForStringEnums[enumType] = true;
- return true;
- }
+ => _warnedForStringEnums.TryAdd(enumType, true);
}
diff --git a/src/EFCore/Diagnostics/MaterializationInterceptionData.cs b/src/EFCore/Diagnostics/MaterializationInterceptionData.cs
index 73cf44c1617..a7041a895b2 100644
--- a/src/EFCore/Diagnostics/MaterializationInterceptionData.cs
+++ b/src/EFCore/Diagnostics/MaterializationInterceptionData.cs
@@ -23,8 +23,7 @@ public readonly struct MaterializationInterceptionData
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- [EntityFrameworkInternal]
- [UsedImplicitly]
+ [EntityFrameworkInternal, UsedImplicitly]
public MaterializationInterceptionData(
MaterializationContext materializationContext,
IEntityType entityType,
diff --git a/src/EFCore/Diagnostics/UpdatingIdentityResolutionInterceptor.cs b/src/EFCore/Diagnostics/UpdatingIdentityResolutionInterceptor.cs
index 8ccfa4bd4f3..a6f5e032ee2 100644
--- a/src/EFCore/Diagnostics/UpdatingIdentityResolutionInterceptor.cs
+++ b/src/EFCore/Diagnostics/UpdatingIdentityResolutionInterceptor.cs
@@ -48,16 +48,14 @@ public virtual void UpdateTrackedInstance(
if (existingEntry.State == EntityState.Added)
{
- foreach (var propertyEntry in tempEntry.Properties.Where(
- e => e.Metadata.GetBeforeSaveBehavior() != PropertySaveBehavior.Throw))
+ foreach (var propertyEntry in tempEntry.Properties.Where(e => e.Metadata.GetBeforeSaveBehavior() != PropertySaveBehavior.Throw))
{
existingEntry.Property(propertyEntry.Metadata.Name).CurrentValue = propertyEntry.CurrentValue;
}
}
else
{
- foreach (var propertyEntry in tempEntry.Properties.Where(
- e => e.Metadata.GetAfterSaveBehavior() != PropertySaveBehavior.Throw))
+ foreach (var propertyEntry in tempEntry.Properties.Where(e => e.Metadata.GetAfterSaveBehavior() != PropertySaveBehavior.Throw))
{
var existingPropertyEntry = existingEntry.Property(propertyEntry.Metadata.Name);
diff --git a/src/EFCore/Diagnostics/WarningsConfiguration.cs b/src/EFCore/Diagnostics/WarningsConfiguration.cs
index 59bf127a98e..6b1060d01ef 100644
--- a/src/EFCore/Diagnostics/WarningsConfiguration.cs
+++ b/src/EFCore/Diagnostics/WarningsConfiguration.cs
@@ -166,7 +166,7 @@ public virtual WarningsConfiguration WithExplicit(
public virtual WarningsConfiguration TryWithExplicit(EventId eventId, WarningBehavior warningBehavior)
=> _explicitBehaviors.ContainsKey(eventId.Id)
? this
- : WithExplicit(new[] { eventId }, warningBehavior);
+ : WithExplicit([eventId], warningBehavior);
///
/// Returns a value indicating whether all of the options used in
diff --git a/src/EFCore/EF.CompileAsyncQuery.cs b/src/EFCore/EF.CompileAsyncQuery.cs
index 10f8afb663c..c08dadd0d1a 100644
--- a/src/EFCore/EF.CompileAsyncQuery.cs
+++ b/src/EFCore/EF.CompileAsyncQuery.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Query.Internal;
namespace Microsoft.EntityFrameworkCore;
diff --git a/src/EFCore/EF.cs b/src/EFCore/EF.cs
index 6a5645e1afa..72b164ada33 100644
--- a/src/EFCore/EF.cs
+++ b/src/EFCore/EF.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore;
///
diff --git a/src/EFCore/EFCore.csproj b/src/EFCore/EFCore.csproj
index ebd55af327c..959949da569 100644
--- a/src/EFCore/EFCore.csproj
+++ b/src/EFCore/EFCore.csproj
@@ -22,6 +22,7 @@ Microsoft.EntityFrameworkCore.DbSet
+
diff --git a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs
index 1fcda68fe55..0602cf9ea5b 100644
--- a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs
+++ b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Query.Internal;
@@ -13,18 +12,17 @@ namespace Microsoft.EntityFrameworkCore;
/// Entity Framework LINQ related extension methods.
///
[UnconditionalSuppressMessage(
- "ReflectionAnalysis",
- "IL2060",
- Justification =
- "MakeGenericMethod is used in this class to create MethodCallExpression nodes, but only if the method in question is called "
- + "from user code - so it's never trimmed. After https://github.com/dotnet/linker/issues/2482 is fixed, the suppression will no "
- + "longer be necessary.")]
-[UnconditionalSuppressMessage(
- "AOT",
- "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.",
- Justification =
- "MakeGenericMethod is used in this class to create MethodCallExpression nodes, but only if the method in question is called "
- + "from user code - so it's never trimmed.")]
+ "ReflectionAnalysis",
+ "IL2060",
+ Justification =
+ "MakeGenericMethod is used in this class to create MethodCallExpression nodes, but only if the method in question is called "
+ + "from user code - so it's never trimmed. After https://github.com/dotnet/linker/issues/2482 is fixed, the suppression will no "
+ + "longer be necessary."), UnconditionalSuppressMessage(
+ "AOT",
+ "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.",
+ Justification =
+ "MakeGenericMethod is used in this class to create MethodCallExpression nodes, but only if the method in question is called "
+ + "from user code - so it's never trimmed.")]
public static class EntityFrameworkQueryableExtensions
{
///
@@ -2429,20 +2427,16 @@ public static async Task> ToHashSetAsync(
internal static readonly MethodInfo IncludeMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(Include))
- .Single(
- mi =>
- mi.GetGenericArguments().Length == 2
- && mi.GetParameters().Any(
- pi => pi.Name == "navigationPropertyPath" && pi.ParameterType != typeof(string)));
+ .Single(mi =>
+ mi.GetGenericArguments().Length == 2
+ && mi.GetParameters().Any(pi => pi.Name == "navigationPropertyPath" && pi.ParameterType != typeof(string)));
internal static readonly MethodInfo NotQuiteIncludeMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(NotQuiteInclude))
- .Single(
- mi =>
- mi.GetGenericArguments().Length == 2
- && mi.GetParameters().Any(
- pi => pi.Name == "navigationPropertyPath" && pi.ParameterType != typeof(string)));
+ .Single(mi =>
+ mi.GetGenericArguments().Length == 2
+ && mi.GetParameters().Any(pi => pi.Name == "navigationPropertyPath" && pi.ParameterType != typeof(string)));
///
/// Specifies related entities to include in the query results. The navigation property to be included is specified starting with the
@@ -2501,20 +2495,18 @@ internal static readonly MethodInfo ThenIncludeAfterEnumerableMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(ThenInclude))
.Where(mi => mi.GetGenericArguments().Length == 3)
- .Single(
- mi =>
- {
- var typeInfo = mi.GetParameters()[0].ParameterType.GenericTypeArguments[1];
- return typeInfo.IsGenericType
- && typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
- });
+ .Single(mi =>
+ {
+ var typeInfo = mi.GetParameters()[0].ParameterType.GenericTypeArguments[1];
+ return typeInfo.IsGenericType
+ && typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
+ });
internal static readonly MethodInfo ThenIncludeAfterReferenceMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(ThenInclude))
- .Single(
- mi => mi.GetGenericArguments().Length == 3
- && mi.GetParameters()[0].ParameterType.GenericTypeArguments[1].IsGenericParameter);
+ .Single(mi => mi.GetGenericArguments().Length == 3
+ && mi.GetParameters()[0].ParameterType.GenericTypeArguments[1].IsGenericParameter);
///
/// Specifies additional related data to be further included based on a related type that was just included.
@@ -2599,9 +2591,7 @@ IEnumerator IEnumerable.GetEnumerator()
internal static readonly MethodInfo StringIncludeMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(Include))
- .Single(
- mi => mi.GetParameters().Any(
- pi => pi.Name == "navigationPropertyPath" && pi.ParameterType == typeof(string)));
+ .Single(mi => mi.GetParameters().Any(pi => pi.Name == "navigationPropertyPath" && pi.ParameterType == typeof(string)));
///
/// Specifies related entities to include in the query results. The navigation property to be included is
@@ -2712,7 +2702,8 @@ public static IQueryable IgnoreQueryFilters(
/// A new query that will not apply any model-level entity query filters.
/// is .
public static IQueryable IgnoreQueryFilters(
- this IQueryable source, [NotParameterized] IReadOnlyCollection filterKeys)
+ this IQueryable source,
+ [NotParameterized] IReadOnlyCollection filterKeys)
where TEntity : class
=> source.Provider is EntityQueryProvider
? source.Provider.CreateQuery(
@@ -2944,8 +2935,8 @@ source.Provider is EntityQueryProvider
///
public static IQueryable TagWithCallSite(
this IQueryable source,
- [NotParameterized] [CallerFilePath] string? filePath = null,
- [NotParameterized] [CallerLineNumber] int lineNumber = 0)
+ [NotParameterized, CallerFilePath] string? filePath = null,
+ [NotParameterized, CallerLineNumber] int lineNumber = 0)
=> source.Provider is EntityQueryProvider
? source.Provider.CreateQuery(
Expression.Call(
@@ -3404,7 +3395,9 @@ public static int ExecuteUpdate(
/// A collection of set property statements specifying properties to update.
/// A to observe while waiting for the task to complete.
/// The total number of rows updated in the database.
- [DynamicDependency("ExecuteUpdate``1(System.Linq.IQueryable{``1},System.Collections.Generic.IReadOnlyList{ITuple})", typeof(EntityFrameworkQueryableExtensions))]
+ [DynamicDependency(
+ "ExecuteUpdate``1(System.Linq.IQueryable{``1},System.Collections.Generic.IReadOnlyList{ITuple})",
+ typeof(EntityFrameworkQueryableExtensions))]
public static Task ExecuteUpdateAsync(
this IQueryable source,
Action> setPropertyCalls,
@@ -3437,8 +3430,7 @@ private static int ExecuteUpdate(this IQueryable source, [NotP
public static readonly MethodInfo ExecuteUpdateMethodInfo
= typeof(EntityFrameworkQueryableExtensions)
.GetMethods(BindingFlags.NonPublic | BindingFlags.Static)
- .Single(
- m => m.Name == nameof(ExecuteUpdate) && m.GetParameters()[1].ParameterType == typeof(IReadOnlyList));
+ .Single(m => m.Name == nameof(ExecuteUpdate) && m.GetParameters()[1].ParameterType == typeof(IReadOnlyList));
#endregion
}
diff --git a/src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs b/src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs
index 25f5b761c2f..255b01a2737 100644
--- a/src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs
+++ b/src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -340,8 +339,8 @@ public static IServiceCollection AddDbContextPool
serviceCollection.TryAddSingleton, DbContextPool>();
serviceCollection.TryAddScoped, ScopedDbContextLease>();
- serviceCollection.TryAddScoped(
- sp => sp.GetRequiredService>().Context);
+ serviceCollection.TryAddScoped(sp
+ => sp.GetRequiredService>().Context);
if (typeof(TContextService) != typeof(TContextImplementation))
{
@@ -1022,8 +1021,8 @@ public static IServiceCollection AddPooledDbContextFactory
AddPoolingOptions(serviceCollection, optionsAction, poolSize);
serviceCollection.TryAddSingleton, DbContextPool>();
- serviceCollection.TryAddSingleton>(
- sp => new PooledDbContextFactory(sp.GetRequiredService>()));
+ serviceCollection.TryAddSingleton>(sp
+ => new PooledDbContextFactory(sp.GetRequiredService>()));
serviceCollection.TryAddScoped(sp => sp.GetRequiredService>().CreateDbContext());
return serviceCollection;
diff --git a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs
index 4400e4b1ff7..58d4cbff5b3 100644
--- a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs
+++ b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Internal;
@@ -231,7 +231,7 @@ static Expression GenerateEqualExpression(
IReadOnlyProperty property,
int i)
=> property.ClrType.IsValueType
- && property.ClrType.UnwrapNullableType() is Type nonNullableType
+ && property.ClrType.UnwrapNullableType() is var nonNullableType
&& !(nonNullableType == typeof(bool) || nonNullableType.IsNumeric() || nonNullableType.IsEnum)
? Infrastructure.ExpressionExtensions.CreateEqualsExpression(
Expression.Call(
diff --git a/src/EFCore/Extensions/Internal/TypeExtensions.cs b/src/EFCore/Extensions/Internal/TypeExtensions.cs
index a867c0afef5..8fd36eaa1bb 100644
--- a/src/EFCore/Extensions/Internal/TypeExtensions.cs
+++ b/src/EFCore/Extensions/Internal/TypeExtensions.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using System.Text;
// ReSharper disable once CheckNamespace
@@ -65,11 +64,10 @@ public static string GenerateParameterName(this Type type)
return defaultPropertyAttribute == null
? null
: type.GetRuntimeProperties()
- .FirstOrDefault(
- pi =>
- pi.Name == defaultPropertyAttribute.MemberName
- && pi.IsIndexerProperty()
- && pi.SetMethod?.GetParameters() is { Length: 2 } parameters
- && parameters[0].ParameterType == typeof(string));
+ .FirstOrDefault(pi =>
+ pi.Name == defaultPropertyAttribute.MemberName
+ && pi.IsIndexerProperty()
+ && pi.SetMethod?.GetParameters() is { Length: 2 } parameters
+ && parameters[0].ParameterType == typeof(string));
}
}
diff --git a/src/EFCore/Extensions/PropertyBaseExtensions.cs b/src/EFCore/Extensions/PropertyBaseExtensions.cs
index 637fd328611..b77df736e58 100644
--- a/src/EFCore/Extensions/PropertyBaseExtensions.cs
+++ b/src/EFCore/Extensions/PropertyBaseExtensions.cs
@@ -21,7 +21,6 @@ public static string Format(this IEnumerable properties,
=> "{"
+ string.Join(
", ",
- properties.Select(
- p => "'" + p.Name + "'" + (includeTypes ? " : " + p.ClrType.DisplayName(fullName: false) : "")))
+ properties.Select(p => "'" + p.Name + "'" + (includeTypes ? " : " + p.ClrType.DisplayName(fullName: false) : "")))
+ "}";
}
diff --git a/src/EFCore/IDbContextFactory.cs b/src/EFCore/IDbContextFactory.cs
index 180d1deb2e7..dcf89959fd2 100644
--- a/src/EFCore/IDbContextFactory.cs
+++ b/src/EFCore/IDbContextFactory.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore;
///
diff --git a/src/EFCore/IEntityTypeConfiguration.cs b/src/EFCore/IEntityTypeConfiguration.cs
index a2368584522..833332b6c77 100644
--- a/src/EFCore/IEntityTypeConfiguration.cs
+++ b/src/EFCore/IEntityTypeConfiguration.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore;
///
diff --git a/src/EFCore/Infrastructure/AnnotatableBase.cs b/src/EFCore/Infrastructure/AnnotatableBase.cs
index 9a061b5a684..5961fd47109 100644
--- a/src/EFCore/Infrastructure/AnnotatableBase.cs
+++ b/src/EFCore/Infrastructure/AnnotatableBase.cs
@@ -276,7 +276,7 @@ protected virtual Annotation CreateAnnotation(string name, object? value)
/// Gets all runtime annotations on the current object.
///
public virtual IEnumerable GetRuntimeAnnotations()
- => _runtimeAnnotations?.OrderBy(p => p.Key).Select(p => p.Value) ?? Enumerable.Empty();
+ => _runtimeAnnotations?.OrderBy(p => p.Key).Select(p => p.Value) ?? [];
///
/// Adds a runtime annotation to this object. Throws if an annotation with the specified name already exists.
diff --git a/src/EFCore/Infrastructure/CoreOptionsExtension.cs b/src/EFCore/Infrastructure/CoreOptionsExtension.cs
index 3c87a8f759b..04ed76bbb07 100644
--- a/src/EFCore/Infrastructure/CoreOptionsExtension.cs
+++ b/src/EFCore/Infrastructure/CoreOptionsExtension.cs
@@ -39,7 +39,6 @@ public class CoreOptionsExtension : IDbContextOptionsExtension
private int? _maxPoolSize;
private TimeSpan _loggingCacheTime = DefaultLoggingCacheTime;
private bool _serviceProviderCachingEnabled = true;
- private DbContextOptionsExtensionInfo? _info;
private IEnumerable? _interceptors;
private IEnumerable? _singletonInterceptors;
private Action? _seed;
@@ -99,8 +98,9 @@ protected CoreOptionsExtension(CoreOptionsExtension copyFrom)
///
/// Information/metadata about the extension.
///
+ [field: AllowNull, MaybeNull]
public virtual DbContextOptionsExtensionInfo Info
- => _info ??= new ExtensionInfo(this);
+ => field ??= new ExtensionInfo(this);
///
/// Override this method in a derived class to ensure that any clone created is also of that class.
@@ -662,7 +662,6 @@ public virtual void Validate(IDbContextOptions options)
private sealed class ExtensionInfo(CoreOptionsExtension extension) : DbContextOptionsExtensionInfo(extension)
{
private int? _serviceProviderHash;
- private string? _logFragment;
private new CoreOptionsExtension Extension
=> (CoreOptionsExtension)base.Extension;
@@ -670,11 +669,12 @@ private sealed class ExtensionInfo(CoreOptionsExtension extension) : DbContextOp
public override bool IsDatabaseProvider
=> false;
+ [field: AllowNull, MaybeNull]
public override string LogFragment
{
get
{
- if (_logFragment == null)
+ if (field == null)
{
var builder = new StringBuilder();
@@ -703,10 +703,10 @@ public override string LogFragment
builder.Append("MaxPoolSize=").Append(Extension._maxPoolSize).Append(' ');
}
- _logFragment = builder.ToString();
+ field = builder.ToString();
}
- return _logFragment;
+ return field;
}
}
diff --git a/src/EFCore/Infrastructure/DatabaseFacade.cs b/src/EFCore/Infrastructure/DatabaseFacade.cs
index e370468294f..8d33d895c6b 100644
--- a/src/EFCore/Infrastructure/DatabaseFacade.cs
+++ b/src/EFCore/Infrastructure/DatabaseFacade.cs
@@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Data.Common;
-using System.Diagnostics.CodeAnalysis;
namespace Microsoft.EntityFrameworkCore.Infrastructure;
@@ -15,7 +14,6 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure;
public class DatabaseFacade : IInfrastructure, IDatabaseFacadeDependenciesAccessor, IResettableService
{
private readonly DbContext _context;
- private IDatabaseFacadeDependencies? _dependencies;
///
/// Initializes a new instance of the class. Instances of this class are typically
@@ -26,8 +24,9 @@ public class DatabaseFacade : IInfrastructure, IDatabaseFacade
public DatabaseFacade(DbContext context)
=> _context = context;
+ [field: AllowNull, MaybeNull]
private IDatabaseFacadeDependencies Dependencies
- => _dependencies ??= _context.GetService();
+ => field ??= _context.GetService();
///
/// Ensures that the database for the context exists.
@@ -204,7 +203,7 @@ public virtual Task EnsureDeletedAsync(CancellationToken cancellationToken
=> Dependencies.DatabaseCreator.EnsureDeletedAsync(cancellationToken);
///
- /// Determines whether or not the database is available and can be connected to.
+ /// Determines whether the database is available and can be connected to.
///
///
///
@@ -227,7 +226,7 @@ public virtual bool CanConnect()
=> Dependencies.DatabaseCreator.CanConnect();
///
- /// Determines whether or not the database is available and can be connected to.
+ /// Determines whether the database is available and can be connected to.
///
///
///
@@ -387,7 +386,7 @@ public virtual IDbContextTransaction? CurrentTransaction
=> Dependencies.TransactionManager.CurrentTransaction;
///
- /// Gets or sets a value indicating whether or not a transaction will be created automatically by
+ /// Gets or sets a value indicating whether a transaction will be created automatically by
/// if none of the 'BeginTransaction' or 'UseTransaction' methods have been called.
///
///
@@ -428,7 +427,7 @@ public virtual bool AutoTransactionsEnabled
}
///
- /// Gets or sets a value indicating whether or not a transaction will be created automatically by
+ /// Gets or sets a value indicating whether a transaction will be created automatically by
/// if neither 'BeginTransaction' nor 'UseTransaction' has been called.
///
///
diff --git a/src/EFCore/Infrastructure/DbContextModelAttribute.cs b/src/EFCore/Infrastructure/DbContextModelAttribute.cs
index b621fc4f117..bebeb262a0c 100644
--- a/src/EFCore/Infrastructure/DbContextModelAttribute.cs
+++ b/src/EFCore/Infrastructure/DbContextModelAttribute.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Infrastructure;
///
diff --git a/src/EFCore/Infrastructure/DbSetProperty.cs b/src/EFCore/Infrastructure/DbSetProperty.cs
index 01481381ccd..590668c2c50 100644
--- a/src/EFCore/Infrastructure/DbSetProperty.cs
+++ b/src/EFCore/Infrastructure/DbSetProperty.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Infrastructure;
///
diff --git a/src/EFCore/Infrastructure/EntityFrameworkMetricsData.cs b/src/EFCore/Infrastructure/EntityFrameworkMetricsData.cs
index 055d1a3056d..33a66eb7550 100644
--- a/src/EFCore/Infrastructure/EntityFrameworkMetricsData.cs
+++ b/src/EFCore/Infrastructure/EntityFrameworkMetricsData.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
diff --git a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs
index b9d52303691..5ca912c5608 100644
--- a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs
+++ b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
@@ -312,9 +311,8 @@ public virtual EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd();
TryAdd();
- TryAdd(
- p => p.GetService()?.FindExtension()?.DbContextLogger
- ?? new NullDbContextLogger());
+ TryAdd(p => p.GetService()?.FindExtension()?.DbContextLogger
+ ?? new NullDbContextLogger());
// This has to be lazy to avoid creating instances that are not disposed
ServiceCollectionMap
diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs
index c65455ea345..3eed5f195a2 100644
--- a/src/EFCore/Infrastructure/ExpressionExtensions.cs
+++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Internal;
@@ -59,9 +58,9 @@ public static MemberExpression MakeMemberAccess(
/// The value that will be assigned.
/// The representing the assignment binding.
[UnconditionalSuppressMessage(
- "ReflectionAnalysis", "IL2077",
- Justification = "AssignBinaryExpression is preserved via DynamicDependency below")]
- [DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Linq.Expressions.AssignBinaryExpression", "System.Linq.Expressions")]
+ "ReflectionAnalysis", "IL2077",
+ Justification = "AssignBinaryExpression is preserved via DynamicDependency below"),
+ DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Linq.Expressions.AssignBinaryExpression", "System.Linq.Expressions")]
public static Expression Assign(
this MemberExpression memberExpression,
Expression valueExpression)
@@ -447,7 +446,7 @@ static Expression AddConvertToObject(Expression expression)
/// The model being used.
/// The given expression, with the top-level member access node removed.
///
- /// if represents a member access, otherwise.
+ /// if represents a member access, otherwise.
///
public static bool IsMemberAccess(
Expression expression,
@@ -464,7 +463,7 @@ public static bool IsMemberAccess(
/// The given expression, with the top-level member access node removed.
/// A representing the member being accessed.
///
- /// if represents a member access, otherwise.
+ /// if represents a member access, otherwise.
///
public static bool IsMemberAccess(
Expression expression,
diff --git a/src/EFCore/Infrastructure/IInternalServiceCollectionMap.cs b/src/EFCore/Infrastructure/IInternalServiceCollectionMap.cs
index de142e5be29..41c4b811209 100644
--- a/src/EFCore/Infrastructure/IInternalServiceCollectionMap.cs
+++ b/src/EFCore/Infrastructure/IInternalServiceCollectionMap.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Infrastructure;
///
diff --git a/src/EFCore/Infrastructure/IndentedStringBuilder.cs b/src/EFCore/Infrastructure/IndentedStringBuilder.cs
index c77d21c3954..c72b20c8f94 100644
--- a/src/EFCore/Infrastructure/IndentedStringBuilder.cs
+++ b/src/EFCore/Infrastructure/IndentedStringBuilder.cs
@@ -291,7 +291,7 @@ public virtual IDisposable SuspendIndent()
=> new IndentSuspender(this);
///
- /// Clones this , copying the built string and current indent level.
+ /// Clones this , copying the built string and current indent level.
///
/// New instance of .
public virtual IndentedStringBuilder Clone()
diff --git a/src/EFCore/Infrastructure/Internal/DbSetFinder.cs b/src/EFCore/Infrastructure/Internal/DbSetFinder.cs
index bab939cc544..e931bebc558 100644
--- a/src/EFCore/Infrastructure/Internal/DbSetFinder.cs
+++ b/src/EFCore/Infrastructure/Internal/DbSetFinder.cs
@@ -30,18 +30,16 @@ private static DbSetProperty[] FindSetsNonCached(Type contextType)
var factory = ClrPropertySetterFactory.Instance;
return contextType.GetRuntimeProperties()
- .Where(
- p => !p.IsStatic()
- && !p.GetIndexParameters().Any()
- && p.DeclaringType != typeof(DbContext)
- && p.PropertyType.GetTypeInfo().IsGenericType
- && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
+ .Where(p => !p.IsStatic()
+ && !p.GetIndexParameters().Any()
+ && p.DeclaringType != typeof(DbContext)
+ && p.PropertyType.GetTypeInfo().IsGenericType
+ && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
.OrderBy(p => p.Name)
- .Select(
- p => new DbSetProperty(
- p.Name,
- p.PropertyType.GenericTypeArguments.Single(),
- p.SetMethod == null ? null : factory.Create(p)))
+ .Select(p => new DbSetProperty(
+ p.Name,
+ p.PropertyType.GenericTypeArguments.Single(),
+ p.SetMethod == null ? null : factory.Create(p)))
.ToArray();
}
}
diff --git a/src/EFCore/Infrastructure/Internal/InternalServiceCollectionMap.cs b/src/EFCore/Infrastructure/Internal/InternalServiceCollectionMap.cs
index 84d1ed9108c..a77a5d7ab53 100644
--- a/src/EFCore/Infrastructure/Internal/InternalServiceCollectionMap.cs
+++ b/src/EFCore/Infrastructure/Internal/InternalServiceCollectionMap.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Internal;
namespace Microsoft.EntityFrameworkCore.Infrastructure.Internal;
diff --git a/src/EFCore/Infrastructure/Internal/LazyLoader.cs b/src/EFCore/Infrastructure/Internal/LazyLoader.cs
index b5c49fc197d..240cc775c29 100644
--- a/src/EFCore/Infrastructure/Internal/LazyLoader.cs
+++ b/src/EFCore/Infrastructure/Internal/LazyLoader.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.EntityFrameworkCore.Internal;
@@ -20,8 +19,11 @@ public class LazyLoader : ILazyLoader, IInjectableService
private bool _disposed;
private bool _detached;
private IDictionary? _loadedStates;
- private readonly Lock _isLoadingLock = new Lock();
- private readonly Dictionary<(object Entity, string NavigationName), TaskCompletionSource> _isLoading = new(NavEntryEqualityComparer.Instance);
+ private readonly Lock _isLoadingLock = new();
+
+ private readonly Dictionary<(object Entity, string NavigationName), TaskCompletionSource> _isLoading = new(
+ NavEntryEqualityComparer.Instance);
+
private static readonly AsyncLocal _isLoadingCallDepth = new();
private HashSet? _nonLazyNavigations;
@@ -118,8 +120,9 @@ public virtual void Load(object entity, [CallerMemberName] string navigationName
ref var refIsLoadingValue = ref CollectionsMarshal.GetValueRefOrAddDefault(_isLoading, navEntry, out exists);
if (!exists)
{
- refIsLoadingValue = new();
+ refIsLoadingValue = new TaskCompletionSource();
}
+
_isLoadingCallDepth.Value++;
isLoadingValue = refIsLoadingValue!;
}
@@ -132,6 +135,7 @@ public virtual void Load(object entity, [CallerMemberName] string navigationName
{
isLoadingValue.Task.Wait();
}
+
_isLoadingCallDepth.Value--;
return;
}
@@ -190,8 +194,9 @@ public virtual async Task LoadAsync(
ref var refIsLoadingValue = ref CollectionsMarshal.GetValueRefOrAddDefault(_isLoading, navEntry, out exists);
if (!exists)
{
- refIsLoadingValue = new();
+ refIsLoadingValue = new TaskCompletionSource();
}
+
_isLoadingCallDepth.Value++;
isLoadingValue = refIsLoadingValue!;
}
@@ -204,6 +209,7 @@ public virtual async Task LoadAsync(
{
await isLoadingValue.Task.WaitAsync(cancellationToken).ConfigureAwait(false);
}
+
_isLoadingCallDepth.Value--;
return;
}
@@ -216,10 +222,10 @@ public virtual async Task LoadAsync(
try
{
await entry.LoadAsync(
- _queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
- ? LoadOptions.ForceIdentityResolution
- : LoadOptions.None,
- cancellationToken).ConfigureAwait(false);
+ _queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
+ ? LoadOptions.ForceIdentityResolution
+ : LoadOptions.None,
+ cancellationToken).ConfigureAwait(false);
}
catch
{
diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs
index 346193b7137..6a578a6df46 100644
--- a/src/EFCore/Infrastructure/ModelValidator.cs
+++ b/src/EFCore/Infrastructure/ModelValidator.cs
@@ -147,13 +147,16 @@ protected virtual void ValidatePropertyMapping(
/// The type base to validate.
/// The model to validate.
/// The logger to use.
- protected virtual void ValidatePropertyMapping(IConventionTypeBase structuralType, IConventionModel model, IDiagnosticsLogger logger)
+ protected virtual void ValidatePropertyMapping(
+ IConventionTypeBase structuralType,
+ IConventionModel model,
+ IDiagnosticsLogger logger)
{
- var unmappedProperty = structuralType.GetDeclaredProperties().FirstOrDefault(
- p => (!ConfigurationSource.Convention.Overrides(p.GetConfigurationSource())
- // Use a better condition for non-persisted properties when issue #14121 is implemented
- || !p.IsImplicitlyCreated())
- && p.FindTypeMapping() == null);
+ var unmappedProperty = structuralType.GetDeclaredProperties().FirstOrDefault(p
+ => (!ConfigurationSource.Convention.Overrides(p.GetConfigurationSource())
+ // Use a better condition for non-persisted properties when issue #14121 is implemented
+ || !p.IsImplicitlyCreated())
+ && p.FindTypeMapping() == null);
if (unmappedProperty != null)
{
@@ -245,9 +248,9 @@ protected virtual void ValidatePropertyMapping(IConventionTypeBase structuralTyp
if ((isAdHoc
|| !entityType.IsKeyless
|| targetSequenceType == null)
- && entityType.GetDerivedTypes().All(
- dt => dt.GetDeclaredNavigations().FirstOrDefault(n => n.Name == clrProperty.GetSimpleMemberName())
- == null)
+ && entityType.GetDerivedTypes().All(dt
+ => dt.GetDeclaredNavigations().FirstOrDefault(n => n.Name == clrProperty.GetSimpleMemberName())
+ == null)
&& (!(targetShared || targetOwned.Value)
|| !targetType.Equals(entityType.ClrType))
&& (!entityType.IsInOwnershipPath(targetType)
@@ -302,7 +305,9 @@ protected virtual void ValidatePropertyMapping(IConventionTypeBase structuralTyp
///
/// The complex property to validate.
/// The logger to use.
- protected virtual void ValidatePropertyMapping(IConventionComplexProperty complexProperty, IDiagnosticsLogger logger)
+ protected virtual void ValidatePropertyMapping(
+ IConventionComplexProperty complexProperty,
+ IDiagnosticsLogger logger)
{
var structuralType = complexProperty.DeclaringType;
@@ -685,6 +690,7 @@ protected virtual void ValidateDiscriminatorValues(IEntityType rootEntityType)
{
ValidateDiscriminatorValues(complexProperty.ComplexType);
}
+
return;
}
@@ -857,11 +863,10 @@ protected virtual void ValidateOwnership(
throw new InvalidOperationException(CoreStrings.OwnedDerivedType(entityType.DisplayName()));
}
- foreach (var referencingFk in entityType.GetReferencingForeignKeys().Where(
- fk => !fk.IsOwnership
- && (fk.PrincipalEntityType != fk.DeclaringEntityType
- || !fk.Properties.SequenceEqual(entityType.FindPrimaryKey()!.Properties))
- && !Contains(fk.DeclaringEntityType.FindOwnership(), fk)))
+ foreach (var referencingFk in entityType.GetReferencingForeignKeys().Where(fk => !fk.IsOwnership
+ && (fk.PrincipalEntityType != fk.DeclaringEntityType
+ || !fk.Properties.SequenceEqual(entityType.FindPrimaryKey()!.Properties))
+ && !Contains(fk.DeclaringEntityType.FindOwnership(), fk)))
{
throw new InvalidOperationException(
CoreStrings.PrincipalOwnedType(
@@ -876,9 +881,9 @@ protected virtual void ValidateOwnership(
entityType.DisplayName()));
}
- foreach (var fk in entityType.GetDeclaredForeignKeys().Where(
- fk => fk is { IsOwnership: false, PrincipalToDependent: not null }
- && !Contains(fk.DeclaringEntityType.FindOwnership(), fk)))
+ foreach (var fk in entityType.GetDeclaredForeignKeys().Where(fk
+ => fk is { IsOwnership: false, PrincipalToDependent: not null }
+ && !Contains(fk.DeclaringEntityType.FindOwnership(), fk)))
{
throw new InvalidOperationException(
CoreStrings.InverseToOwnedType(
@@ -953,9 +958,8 @@ protected virtual void ValidateForeignKeys(
static bool ContainedInForeignKeyForAllConcreteTypes(IEntityType entityType, IProperty property)
=> entityType.ClrType.IsAbstract
&& entityType.GetDerivedTypes().Where(t => !t.ClrType.IsAbstract)
- .All(
- d => d.GetForeignKeys()
- .Any(fk => fk.Properties.Contains(property)));
+ .All(d => d.GetForeignKeys()
+ .Any(fk => fk.Properties.Contains(property)));
}
///
@@ -1055,11 +1059,12 @@ static void Validate(ITypeBase structuralType)
if (complexProperty.IsCollection
&& !complexProperty.ClrType.GetGenericTypeImplementations(typeof(IList<>)).Any())
{
- throw new InvalidOperationException(CoreStrings.NonListCollection(
- complexProperty.DeclaringType.DisplayName(),
- complexProperty.Name,
- complexProperty.ClrType.ShortDisplayName(),
- $"IList<{complexProperty.ComplexType.ClrType.ShortDisplayName()}>"));
+ throw new InvalidOperationException(
+ CoreStrings.NonListCollection(
+ complexProperty.DeclaringType.DisplayName(),
+ complexProperty.Name,
+ complexProperty.ClrType.ShortDisplayName(),
+ $"IList<{complexProperty.ComplexType.ClrType.ShortDisplayName()}>"));
}
Validate(complexProperty.ComplexType);
@@ -1232,10 +1237,9 @@ protected virtual void ValidateQueryFilters(
// So we don't check navigations there. We assume the owner will propagate filtering
var requiredNavigationWithQueryFilter = entityType
.GetNavigations()
- .FirstOrDefault(
- n => n is { IsCollection: false, ForeignKey.IsRequired: true, IsOnDependent: true }
- && n.ForeignKey.PrincipalEntityType.GetRootType().GetDeclaredQueryFilters().Count > 0
- && n.ForeignKey.DeclaringEntityType.GetRootType().GetDeclaredQueryFilters().Count == 0);
+ .FirstOrDefault(n => n is { IsCollection: false, ForeignKey.IsRequired: true, IsOnDependent: true }
+ && n.ForeignKey.PrincipalEntityType.GetRootType().GetDeclaredQueryFilters().Count > 0
+ && n.ForeignKey.DeclaringEntityType.GetRootType().GetDeclaredQueryFilters().Count == 0);
if (requiredNavigationWithQueryFilter != null)
{
diff --git a/src/EFCore/Infrastructure/PooledDbContextFactory.cs b/src/EFCore/Infrastructure/PooledDbContextFactory.cs
index c99a8b878b9..6ceebdf2930 100644
--- a/src/EFCore/Infrastructure/PooledDbContextFactory.cs
+++ b/src/EFCore/Infrastructure/PooledDbContextFactory.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Internal;
namespace Microsoft.EntityFrameworkCore.Infrastructure;
diff --git a/src/EFCore/Metadata/RuntimeAnnotatableBase.cs b/src/EFCore/Infrastructure/RuntimeAnnotatableBase.cs
similarity index 99%
rename from src/EFCore/Metadata/RuntimeAnnotatableBase.cs
rename to src/EFCore/Infrastructure/RuntimeAnnotatableBase.cs
index ebe86f5b23e..a80ebb2cb9e 100644
--- a/src/EFCore/Metadata/RuntimeAnnotatableBase.cs
+++ b/src/EFCore/Infrastructure/RuntimeAnnotatableBase.cs
@@ -204,7 +204,7 @@ protected virtual Annotation CreateAnnotation(string name, object? value)
///
public virtual IEnumerable GetRuntimeAnnotations()
=> _runtimeAnnotations?.OrderBy(p => p.Key, StringComparer.Ordinal).Select(p => p.Value)
- ?? Enumerable.Empty();
+ ?? [];
///
/// Adds a runtime annotation to this object. Throws if an annotation with the specified name already exists.
diff --git a/src/EFCore/Infrastructure/ServiceCollectionMap.cs b/src/EFCore/Infrastructure/ServiceCollectionMap.cs
index 82639bfc533..be346fa4e72 100644
--- a/src/EFCore/Infrastructure/ServiceCollectionMap.cs
+++ b/src/EFCore/Infrastructure/ServiceCollectionMap.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
namespace Microsoft.EntityFrameworkCore.Infrastructure;
diff --git a/src/EFCore/Internal/DbContextFactory.cs b/src/EFCore/Internal/DbContextFactory.cs
index 0d266e2c5c1..3406d7aa998 100644
--- a/src/EFCore/Internal/DbContextFactory.cs
+++ b/src/EFCore/Internal/DbContextFactory.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Internal;
///
diff --git a/src/EFCore/Internal/DbContextLease.cs b/src/EFCore/Internal/DbContextLease.cs
index 925493151e6..d8b9db18128 100644
--- a/src/EFCore/Internal/DbContextLease.cs
+++ b/src/EFCore/Internal/DbContextLease.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Internal;
///
diff --git a/src/EFCore/Internal/DbContextPool.cs b/src/EFCore/Internal/DbContextPool.cs
index eba778ba06c..ac42f86e9a1 100644
--- a/src/EFCore/Internal/DbContextPool.cs
+++ b/src/EFCore/Internal/DbContextPool.cs
@@ -55,7 +55,7 @@ private static Func CreateActivator(DbContextOptions option
.Where(c => c is { IsStatic: false, IsPublic: true } && c.GetParameters().Length > 0).ToArray();
if (constructors.Length == 1
- && constructors[0].GetParameters() is { } parameters
+ && constructors[0].GetParameters() is var parameters
&& parameters.Any(p => p.ParameterType == typeof(DbContextOptions) || p.ParameterType == typeof(DbContextOptions)))
{
if (parameters.Length == 1)
diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs
index d7b3ddde953..cd9b61b29d6 100644
--- a/src/EFCore/Internal/DbContextServices.cs
+++ b/src/EFCore/Internal/DbContextServices.cs
@@ -18,8 +18,6 @@ public class DbContextServices : IDbContextServices
private IServiceProvider? _scopedProvider;
private DbContextOptions? _contextOptions;
private ICurrentDbContext? _currentContext;
- private IModel? _model;
- private IModel? _designTimeModel;
private bool _inOnModelCreating;
///
@@ -156,8 +154,9 @@ public virtual ICurrentDbContext CurrentContext
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
+ [field: AllowNull, MaybeNull]
public virtual IModel Model
- => _model ??= CreateModel(designTime: false);
+ => field ??= CreateModel(designTime: false);
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -165,8 +164,9 @@ public virtual IModel Model
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
+ [field: AllowNull, MaybeNull]
public virtual IModel DesignTimeModel
- => _designTimeModel ??= CreateModel(designTime: true);
+ => field ??= CreateModel(designTime: true);
private CoreOptionsExtension? CoreOptions
=> _contextOptions?.FindExtension();
diff --git a/src/EFCore/Internal/EntityFinder.cs b/src/EFCore/Internal/EntityFinder.cs
index 980d38d8ef5..904bf22ddf4 100644
--- a/src/EFCore/Internal/EntityFinder.cs
+++ b/src/EFCore/Internal/EntityFinder.cs
@@ -148,8 +148,8 @@ public virtual IEnumerable GetEntries(IProperty
if (TryFindByKey(property, propertyValue, out var entry))
{
return entry != null
- ? new[] { entry }
- : Enumerable.Empty();
+ ? [entry]
+ : [];
}
if (TryGetByForeignKey(property, propertyValue, out var entries))
@@ -216,8 +216,8 @@ public virtual IEnumerable GetEntries(IEnumerable();
+ ? [entry]
+ : [];
}
if (TryGetByForeignKey(propertiesList, valuesList, out var entries))
@@ -802,7 +802,7 @@ private static Expression> BuildObjectLambda(IReadOnlyList entityType.FindOwnership() is IForeignKey ownership
+ => entityType.FindOwnership() is { } ownership
? BuildQueryRoot(ownership.PrincipalEntityType, entityType, ownership.PrincipalToDependent!.Name)
: entityType.HasSharedClrType
? (IQueryable)_setCache.GetOrAddSet(_setSource, entityType.Name, entityType.ClrType)
diff --git a/src/EFCore/Internal/IDbSetCache.cs b/src/EFCore/Internal/IDbSetCache.cs
index f988750347e..3d2e00f9f00 100644
--- a/src/EFCore/Internal/IDbSetCache.cs
+++ b/src/EFCore/Internal/IDbSetCache.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Internal;
///
diff --git a/src/EFCore/Internal/IDbSetSource.cs b/src/EFCore/Internal/IDbSetSource.cs
index dda703c0107..10f3191d7ea 100644
--- a/src/EFCore/Internal/IDbSetSource.cs
+++ b/src/EFCore/Internal/IDbSetSource.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Internal;
///
diff --git a/src/EFCore/Internal/InternalDbSet.cs b/src/EFCore/Internal/InternalDbSet.cs
index 907acb7568a..66ab6fa869e 100644
--- a/src/EFCore/Internal/InternalDbSet.cs
+++ b/src/EFCore/Internal/InternalDbSet.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
@@ -26,10 +25,7 @@ public class InternalDbSet<[DynamicallyAccessedMembers(IEntityType.DynamicallyAc
{
private readonly DbContext _context;
private readonly string? _entityTypeName;
- private IEntityType? _entityType;
- private EntityQueryable? _entityQueryable;
private LocalView? _localView;
- private IEntityFinder? _finder;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -51,20 +47,21 @@ public InternalDbSet(DbContext context, string? entityTypeName)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
+ [field: AllowNull, MaybeNull]
public override IEntityType EntityType
{
get
{
- if (_entityType != null)
+ if (field != null)
{
- return _entityType;
+ return field;
}
- _entityType = _entityTypeName != null
+ field = _entityTypeName != null
? _context.Model.FindEntityType(_entityTypeName)
: _context.Model.FindEntityType(typeof(TEntity));
- if (_entityType == null)
+ if (field == null)
{
if (_context.Model.IsShared(typeof(TEntity)))
{
@@ -82,25 +79,25 @@ public override IEntityType EntityType
throw new InvalidOperationException(CoreStrings.InvalidSetType(typeof(TEntity).ShortDisplayName()));
}
- if (_entityType.IsOwned())
+ if (field.IsOwned())
{
var message = CoreStrings.InvalidSetTypeOwned(
- _entityType.DisplayName(), _entityType.FindOwnership()!.PrincipalEntityType.DisplayName());
- _entityType = null;
+ field.DisplayName(), field.FindOwnership()!.PrincipalEntityType.DisplayName());
+ field = null;
throw new InvalidOperationException(message);
}
- if (_entityType.ClrType != typeof(TEntity))
+ if (field.ClrType != typeof(TEntity))
{
var message = CoreStrings.DbSetIncorrectGenericType(
- _entityType.ShortName(), _entityType.ClrType.ShortDisplayName(), typeof(TEntity).ShortDisplayName());
- _entityType = null;
+ field.ShortName(), field.ClrType.ShortDisplayName(), typeof(TEntity).ShortDisplayName());
+ field = null;
throw new InvalidOperationException(message);
}
- return _entityType;
+ return field;
}
}
@@ -116,6 +113,7 @@ private void CheckKey()
}
}
+ [field: AllowNull, MaybeNull]
private EntityQueryable EntityQueryable
{
get
@@ -123,7 +121,7 @@ private EntityQueryable EntityQueryable
CheckState();
return NonCapturingLazyInitializer.EnsureInitialized(
- ref _entityQueryable,
+ ref field,
this,
static internalSet => internalSet.CreateEntityQueryable());
}
@@ -449,21 +447,22 @@ public override EntityEntry Entry(TEntity entity)
return entry;
}
+ [field: AllowNull, MaybeNull]
private IEntityFinder Finder
{
get
{
- if (_finder == null)
+ if (field == null)
{
if (EntityType.FindPrimaryKey() == null)
{
throw new InvalidOperationException(CoreStrings.InvalidSetKeylessOperation(EntityType.DisplayName()));
}
- _finder = (IEntityFinder)_context.GetDependencies().EntityFinderFactory.Create(EntityType);
+ field = (IEntityFinder)_context.GetDependencies().EntityFinderFactory.Create(EntityType);
}
- return _finder;
+ return field;
}
}
diff --git a/src/EFCore/Metadata/AdHocMapper.cs b/src/EFCore/Metadata/AdHocMapper.cs
index 73e041ca4ea..2e3a25cba26 100644
--- a/src/EFCore/Metadata/AdHocMapper.cs
+++ b/src/EFCore/Metadata/AdHocMapper.cs
@@ -22,8 +22,6 @@ namespace Microsoft.EntityFrameworkCore.Metadata;
///
public class AdHocMapper : IAdHocMapper
{
- private ConventionSet? _conventionSet;
-
///
/// Do not call this constructor directly from either provider or application code as it may change
/// as new dependencies are added. Instead, use this type in your constructor so that an instance
@@ -76,8 +74,9 @@ public virtual ConventionSet BuildConventionSet()
return conventionSet;
}
+ [field: AllowNull, MaybeNull]
private ConventionSet ConventionSet
- => (_conventionSet ??= BuildConventionSet());
+ => (field ??= BuildConventionSet());
///
public virtual RuntimeEntityType GetOrAddEntityType(Type clrType)
diff --git a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs
index b73b48e0423..66045f00bcd 100644
--- a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs
+++ b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
///
diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs
index 75a0eedc2e0..f46fdca9026 100644
--- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs
+++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
///
diff --git a/src/EFCore/Metadata/Builders/ComplexCollectionBuilder.cs b/src/EFCore/Metadata/Builders/ComplexCollectionBuilder.cs
index e27b4011792..8fa60e248dc 100644
--- a/src/EFCore/Metadata/Builders/ComplexCollectionBuilder.cs
+++ b/src/EFCore/Metadata/Builders/ComplexCollectionBuilder.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
@@ -262,7 +261,7 @@ public virtual ComplexCollectionTypePropertyBuilder IndexerProperty(
{
Check.NotNull(propertyType);
- return new(
+ return new ComplexCollectionTypePropertyBuilder(
TypeBuilder.IndexerProperty(
propertyType,
Check.NotEmpty(propertyName), ConfigurationSource.Explicit)!.Metadata);
@@ -674,7 +673,9 @@ public virtual ComplexCollectionBuilder ComplexCollection(string propertyName, A
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public virtual ComplexCollectionBuilder ComplexCollection(string propertyName, Action> buildAction)
+ public virtual ComplexCollectionBuilder ComplexCollection(
+ string propertyName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
{
@@ -703,7 +704,9 @@ public virtual ComplexCollectionBuilder ComplexCollection(s
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
public virtual ComplexCollectionBuilder ComplexCollection(
- string propertyName, string complexTypeName, Action> buildAction)
+ string propertyName,
+ string complexTypeName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
{
@@ -729,7 +732,10 @@ public virtual ComplexCollectionBuilder ComplexCollection(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// The same builder instance so that multiple configuration calls can be chained.
- public virtual ComplexCollectionBuilder ComplexCollection(Type propertyType, string propertyName, Action buildAction)
+ public virtual ComplexCollectionBuilder ComplexCollection(
+ Type propertyType,
+ string propertyName,
+ Action buildAction)
{
Check.NotNull(buildAction);
@@ -754,7 +760,11 @@ public virtual ComplexCollectionBuilder ComplexCollection(Type propertyType, str
/// The name of the complex type.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public virtual ComplexCollectionBuilder ComplexCollection(Type propertyType, string propertyName, string complexTypeName, Action buildAction)
+ public virtual ComplexCollectionBuilder ComplexCollection(
+ Type propertyType,
+ string propertyName,
+ string complexTypeName,
+ Action buildAction)
{
Check.NotNull(buildAction);
diff --git a/src/EFCore/Metadata/Builders/ComplexCollectionBuilder`.cs b/src/EFCore/Metadata/Builders/ComplexCollectionBuilder`.cs
index 80571690313..71cf58a58ad 100644
--- a/src/EFCore/Metadata/Builders/ComplexCollectionBuilder`.cs
+++ b/src/EFCore/Metadata/Builders/ComplexCollectionBuilder`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
///
@@ -32,7 +30,6 @@ public ComplexCollectionBuilder(IMutableComplexProperty complexProperty)
{
}
-
///
/// Adds or updates an annotation on the complex property. If an annotation with the key specified in
/// already exists its value will be updated.
@@ -72,7 +69,8 @@ public ComplexCollectionBuilder(IMutableComplexProperty complexProperty)
/// blog => blog.Url ).
///
/// An object that can be used to configure the property.
- public virtual ComplexCollectionTypePropertyBuilder Property(Expression> propertyExpression)
+ public virtual ComplexCollectionTypePropertyBuilder Property(
+ Expression> propertyExpression)
=> new(
TypeBuilder.Property(
Check.NotNull(propertyExpression).GetMemberAccess(), ConfigurationSource.Explicit)!
@@ -446,7 +444,9 @@ public virtual ComplexCollectionBuilder ComplexProperty(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public new virtual ComplexCollectionBuilder ComplexCollection(string propertyName, Action buildAction)
+ public new virtual ComplexCollectionBuilder ComplexCollection(
+ string propertyName,
+ Action buildAction)
=> (ComplexCollectionBuilder)base.ComplexCollection(propertyName, buildAction);
///
@@ -466,7 +466,8 @@ public virtual ComplexCollectionBuilder ComplexProperty(
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
public new virtual ComplexCollectionBuilder ComplexCollection(
- string propertyName, Action> buildAction)
+ string propertyName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
=> (ComplexCollectionBuilder)base.ComplexCollection(propertyName, buildAction);
@@ -511,7 +512,10 @@ public virtual ComplexCollectionBuilder ComplexProperty(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public new virtual ComplexCollectionBuilder ComplexCollection(Type propertyType, string propertyName, Action buildAction)
+ public new virtual ComplexCollectionBuilder ComplexCollection(
+ Type propertyType,
+ string propertyName,
+ Action buildAction)
=> (ComplexCollectionBuilder)base.ComplexCollection(propertyType, propertyName, buildAction);
///
@@ -531,7 +535,10 @@ public virtual ComplexCollectionBuilder ComplexProperty(
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
public new virtual ComplexCollectionBuilder ComplexCollection(
- Type propertyType, string propertyName, string complexTypeName, Action buildAction)
+ Type propertyType,
+ string propertyName,
+ string complexTypeName,
+ Action buildAction)
=> (ComplexCollectionBuilder)base.ComplexCollection(propertyType, complexTypeName, propertyName, buildAction);
///
diff --git a/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder.cs b/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder.cs
index 6a27c5dbb2d..4a93657bf60 100644
--- a/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder.cs
+++ b/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
diff --git a/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder`.cs b/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder`.cs
index de6fd0abe56..9bc135f7912 100644
--- a/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder`.cs
+++ b/src/EFCore/Metadata/Builders/ComplexCollectionTypePropertyBuilder`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
///
diff --git a/src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs b/src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs
index c2f4ba61d2a..ab082ed3c08 100644
--- a/src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs
+++ b/src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
@@ -712,7 +711,9 @@ public virtual ComplexPropertyBuilder ComplexCollection(string propertyName, Act
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public virtual ComplexPropertyBuilder ComplexCollection(string propertyName, Action> buildAction)
+ public virtual ComplexPropertyBuilder ComplexCollection(
+ string propertyName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
{
@@ -741,7 +742,9 @@ public virtual ComplexPropertyBuilder ComplexCollection(str
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
public virtual ComplexPropertyBuilder ComplexCollection(
- string propertyName, string complexTypeName, Action> buildAction)
+ string propertyName,
+ string complexTypeName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
{
@@ -767,7 +770,10 @@ public virtual ComplexPropertyBuilder ComplexCollection(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public virtual ComplexPropertyBuilder ComplexCollection(Type propertyType, string propertyName, Action buildAction)
+ public virtual ComplexPropertyBuilder ComplexCollection(
+ Type propertyType,
+ string propertyName,
+ Action buildAction)
{
Check.NotNull(buildAction);
@@ -792,7 +798,11 @@ public virtual ComplexPropertyBuilder ComplexCollection(Type propertyType, strin
/// The name of the complex type.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public virtual ComplexPropertyBuilder ComplexCollection(Type propertyType, string propertyName, string complexTypeName, Action buildAction)
+ public virtual ComplexPropertyBuilder ComplexCollection(
+ Type propertyType,
+ string propertyName,
+ string complexTypeName,
+ Action buildAction)
{
Check.NotNull(buildAction);
diff --git a/src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs b/src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs
index 8ece80c7f6f..733198f0262 100644
--- a/src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs
+++ b/src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics.CodeAnalysis;
-
namespace Microsoft.EntityFrameworkCore.Metadata.Builders;
///
@@ -488,7 +486,9 @@ public virtual ComplexPropertyBuilder ComplexProperty(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public new virtual ComplexPropertyBuilder ComplexCollection(string propertyName, Action> buildAction)
+ public new virtual ComplexPropertyBuilder ComplexCollection(
+ string propertyName,
+ Action> buildAction)
where TProperty : IEnumerable
where TElement : notnull
=> (ComplexPropertyBuilder)base.ComplexCollection(propertyName, buildAction);
@@ -533,7 +533,10 @@ public virtual ComplexPropertyBuilder ComplexProperty(
/// The name of the property to be configured.
/// An action that performs configuration of the property.
/// An object that can be used to configure the property.
- public new virtual ComplexPropertyBuilder ComplexCollection(Type propertyType, string propertyName, Action buildAction)
+ public new virtual ComplexPropertyBuilder