Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Flow query tracking behavior to materialization interceptor #29928

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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