Skip to content

Commit

Permalink
Flow query tracking behavior to materialization interceptor (#29928)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Dec 29, 2022
1 parent a61c467 commit 63d261f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/EFCore/Diagnostics/MaterializationInterceptionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public readonly struct MaterializationInterceptionData
public MaterializationInterceptionData(
MaterializationContext materializationContext,
IEntityType entityType,
QueryTrackingBehavior? queryTrackingBehavior,
Dictionary<IPropertyBase, (object TypedAccessor, Func<MaterializationContext, object?> Accessor)> valueAccessor)
{
_materializationContext = materializationContext;
_valueAccessor = valueAccessor;
EntityType = entityType;
QueryTrackingBehavior = queryTrackingBehavior;
}

/// <summary>
Expand All @@ -46,6 +48,11 @@ public DbContext Context
/// </summary>
public IEntityType EntityType { get; }

/// <summary>
/// The query tracking behavior, or <see langword="null" /> if this materialization is not from a query.
/// </summary>
public QueryTrackingBehavior? QueryTrackingBehavior { get; }

/// <summary>
/// Gets the property value for the property with the given name.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore/Query/Internal/EntityMaterializerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private static readonly ConstructorInfo MaterializationInterceptionDataConstruct
{
typeof(MaterializationContext),
typeof(IEntityType),
typeof(QueryTrackingBehavior?),
typeof(Dictionary<IPropertyBase, (object, Func<MaterializationContext, object?>)>)
})!;

Expand Down Expand Up @@ -242,6 +243,7 @@ private static Expression CreateInterceptionMaterializeExpression(
MaterializationInterceptionDataConstructor,
materializationContextExpression,
Expression.Constant(entityType),
Expression.Constant(bindingInfo.QueryTrackingBehavior, typeof(QueryTrackingBehavior?)),
accessorDictionaryVariable)),
Expression.Assign(
creatingResultVariable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ 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);
Assert.Equal(QueryTrackingBehavior.TrackAll, data.QueryTrackingBehavior);

var idProperty = data.EntityType.FindProperty(nameof(Book.Id))!;
var id = data.GetPropertyValue<Guid>(nameof(Book.Id))!;
Expand Down Expand Up @@ -189,6 +190,7 @@ 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);
Assert.Equal(QueryTrackingBehavior.TrackAll, data.QueryTrackingBehavior);

var idProperty = data.EntityType.FindProperty(nameof(Pamphlet.Id))!;
var id = data.GetPropertyValue<Guid>(nameof(Pamphlet.Id))!;
Expand Down

0 comments on commit 63d261f

Please sign in to comment.