From 0b4ccc95222c670cfbd4880bd43947f2173f5fe7 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Mon, 20 Jun 2022 20:55:26 +0100 Subject: [PATCH] Review updates. --- .../Diagnostics/IDbCommandInterceptor.cs | 4 +- .../Diagnostics/IDbConnectionInterceptor.cs | 20 +++++----- .../Diagnostics/IDbTransactionInterceptor.cs | 40 +++++++++---------- .../IMaterializationInterceptor.cs | 4 +- .../MaterializationInterceptionData.cs | 25 +----------- .../Internal/EntityMaterializerSource.cs | 2 +- .../MaterializationInterceptionTestBase.cs | 10 ----- 7 files changed, 37 insertions(+), 68 deletions(-) diff --git a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs index 70110d23f3a..2d10f232a9e 100644 --- a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs @@ -424,8 +424,8 @@ Task CommandFailedAsync(DbCommand command, CommandErrorEventData eventData, Canc /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. diff --git a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs index cc153d9dbc0..1a49eb2c1cf 100644 --- a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs @@ -81,8 +81,8 @@ DbConnection ConnectionCreated(ConnectionCreatedEventData eventData, DbConnectio /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -103,8 +103,8 @@ InterceptionResult ConnectionOpening(DbConnection connection, ConnectionEventDat /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -149,8 +149,8 @@ Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData event /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -170,8 +170,8 @@ InterceptionResult ConnectionClosing(DbConnection connection, ConnectionEventDat /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -230,8 +230,8 @@ InterceptionResult ConnectionDisposing(DbConnection connection, ConnectionEventD /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. diff --git a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs index c34afbc0811..4c64f6f9e03 100644 --- a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs @@ -185,8 +185,8 @@ ValueTask TransactionUsedAsync( /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -217,8 +217,8 @@ void TransactionCommitted(DbTransaction transaction, TransactionEndEventData eve /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -257,8 +257,8 @@ Task TransactionCommittedAsync( /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -289,8 +289,8 @@ void TransactionRolledBack(DbTransaction transaction, TransactionEndEventData ev /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -329,8 +329,8 @@ Task TransactionRolledBackAsync( /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -360,8 +360,8 @@ void CreatedSavepoint(DbTransaction transaction, TransactionEventData eventData) /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -400,8 +400,8 @@ Task CreatedSavepointAsync( /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -434,8 +434,8 @@ void RolledBackToSavepoint(DbTransaction transaction, TransactionEventData event /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -474,8 +474,8 @@ Task RolledBackToSavepointAsync( /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -505,8 +505,8 @@ void ReleasedSavepoint(DbTransaction transaction, TransactionEventData eventData /// /// A to observe while waiting for the task to complete. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is , then EF will continue as normal. + /// If is , then EF will suppress the operation /// it was about to perform. /// An implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. diff --git a/src/EFCore/Diagnostics/IMaterializationInterceptor.cs b/src/EFCore/Diagnostics/IMaterializationInterceptor.cs index 9fe38f8cd28..e3b37c915f5 100644 --- a/src/EFCore/Diagnostics/IMaterializationInterceptor.cs +++ b/src/EFCore/Diagnostics/IMaterializationInterceptor.cs @@ -62,8 +62,8 @@ object CreatedInstance(MaterializationInterceptionData materializationData, obje /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will not set any property values. + /// If is , then EF will continue as normal. + /// If is , then EF will not set any property values. /// An implementation of this method for any interceptor that is not attempting to suppress /// setting property values must return the value passed in. /// diff --git a/src/EFCore/Diagnostics/MaterializationInterceptionData.cs b/src/EFCore/Diagnostics/MaterializationInterceptionData.cs index 62596cb207c..0532852e330 100644 --- a/src/EFCore/Diagnostics/MaterializationInterceptionData.cs +++ b/src/EFCore/Diagnostics/MaterializationInterceptionData.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; public readonly struct MaterializationInterceptionData { private readonly MaterializationContext _materializationContext; - private readonly IDictionary Accessor)> _valueAccessor; + private readonly Dictionary Accessor)> _valueAccessor; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -28,7 +28,7 @@ public readonly struct MaterializationInterceptionData public MaterializationInterceptionData( MaterializationContext materializationContext, IEntityType entityType, - IDictionary Accessor)> valueAccessor) + Dictionary Accessor)> valueAccessor) { _materializationContext = materializationContext; _valueAccessor = valueAccessor; @@ -106,25 +106,4 @@ public T GetPropertyValue(IPropertyBase property) /// The property value. public object? GetPropertyValue(IPropertyBase property) => _valueAccessor[property].Accessor(_materializationContext); - - /// - /// Creates a dictionary containing a snapshot of all property values for the instance being materialized. - /// - /// - /// Note that this method causes a new dictionary to be created, and copies all values into that dictionary. This can - /// be less efficient than getting values individually, especially if the non-boxing generic overloads - /// or can be used. - /// - /// The values of properties for the entity instance. - public IReadOnlyDictionary CreateValuesDictionary() - { - var dictionary = new Dictionary(); - - foreach (var property in EntityType.GetServiceProperties().Cast().Concat(EntityType.GetProperties())) - { - dictionary[property] = GetPropertyValue(property); - } - - return dictionary; - } } diff --git a/src/EFCore/Query/Internal/EntityMaterializerSource.cs b/src/EFCore/Query/Internal/EntityMaterializerSource.cs index 689979dcbe6..ea809e9d3da 100644 --- a/src/EFCore/Query/Internal/EntityMaterializerSource.cs +++ b/src/EFCore/Query/Internal/EntityMaterializerSource.cs @@ -151,7 +151,7 @@ private static readonly ConstructorInfo MaterializationInterceptionDataConstruct { typeof(MaterializationContext), typeof(IEntityType), - typeof(IDictionary)>) + typeof(Dictionary)>) })!; private static readonly MethodInfo CreatingInstanceMethod diff --git a/test/EFCore.Specification.Tests/MaterializationInterceptionTestBase.cs b/test/EFCore.Specification.Tests/MaterializationInterceptionTestBase.cs index 23860cbb2ab..f4cd7c0f1c0 100644 --- a/test/EFCore.Specification.Tests/MaterializationInterceptionTestBase.cs +++ b/test/EFCore.Specification.Tests/MaterializationInterceptionTestBase.cs @@ -86,14 +86,11 @@ public virtual void Intercept_query_materialization_for_empty_constructor(bool i Assert.Same(context, data.Context); Assert.Same(data.Context.Model.FindEntityType(typeof(Book)), data.EntityType); - var valuesDictionary = data.CreateValuesDictionary(); - var idProperty = data.EntityType.FindProperty(nameof(Book.Id))!; var id = data.GetPropertyValue(nameof(Book.Id))!; Assert.Equal(id, data.GetPropertyValue(nameof(Book.Id))); Assert.Equal(id, data.GetPropertyValue(idProperty)); Assert.Equal(id, data.GetPropertyValue(idProperty)); - Assert.Equal(id, valuesDictionary[idProperty]); ids.Add(id); var titleProperty = data.EntityType.FindProperty(nameof(Book.Title))!; @@ -101,7 +98,6 @@ public virtual void Intercept_query_materialization_for_empty_constructor(bool i Assert.Equal(title, data.GetPropertyValue(nameof(Book.Title))); Assert.Equal(title, data.GetPropertyValue(titleProperty)); Assert.Equal(title, data.GetPropertyValue(titleProperty)); - Assert.Equal(title, valuesDictionary[titleProperty]); titles.Add(title); var authorProperty = data.EntityType.FindProperty("Author")!; @@ -109,7 +105,6 @@ public virtual void Intercept_query_materialization_for_empty_constructor(bool i Assert.Equal(author, data.GetPropertyValue("Author")); Assert.Equal(author, data.GetPropertyValue(authorProperty)); Assert.Equal(author, data.GetPropertyValue(authorProperty)); - Assert.Equal(author, valuesDictionary[authorProperty]); authors.Add(author); switch (method) @@ -197,14 +192,11 @@ public virtual void Intercept_query_materialization_for_full_constructor(bool in Assert.Same(context, data.Context); Assert.Same(data.Context.Model.FindEntityType(typeof(Pamphlet)), data.EntityType); - var valuesDictionary = data.CreateValuesDictionary(); - var idProperty = data.EntityType.FindProperty(nameof(Pamphlet.Id))!; var id = data.GetPropertyValue(nameof(Pamphlet.Id))!; Assert.Equal(id, data.GetPropertyValue(nameof(Pamphlet.Id))); Assert.Equal(id, data.GetPropertyValue(idProperty)); Assert.Equal(id, data.GetPropertyValue(idProperty)); - Assert.Equal(id, valuesDictionary[idProperty]); ids.Add(id); var titleProperty = data.EntityType.FindProperty(nameof(Pamphlet.Title))!; @@ -212,7 +204,6 @@ public virtual void Intercept_query_materialization_for_full_constructor(bool in Assert.Equal(title, data.GetPropertyValue(nameof(Pamphlet.Title))); Assert.Equal(title, data.GetPropertyValue(titleProperty)); Assert.Equal(title, data.GetPropertyValue(titleProperty)); - Assert.Equal(title, valuesDictionary[titleProperty]); titles.Add(title); var authorProperty = data.EntityType.FindProperty("Author")!; @@ -220,7 +211,6 @@ public virtual void Intercept_query_materialization_for_full_constructor(bool in Assert.Equal(author, data.GetPropertyValue("Author")); Assert.Equal(author, data.GetPropertyValue(authorProperty)); Assert.Equal(author, data.GetPropertyValue(authorProperty)); - Assert.Equal(author, valuesDictionary[authorProperty]); authors.Add(author); switch (method)