Skip to content

Commit 63d261f

Browse files
authored
Flow query tracking behavior to materialization interceptor (#29928)
1 parent a61c467 commit 63d261f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/EFCore/Diagnostics/MaterializationInterceptionData.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public readonly struct MaterializationInterceptionData
2828
public MaterializationInterceptionData(
2929
MaterializationContext materializationContext,
3030
IEntityType entityType,
31+
QueryTrackingBehavior? queryTrackingBehavior,
3132
Dictionary<IPropertyBase, (object TypedAccessor, Func<MaterializationContext, object?> Accessor)> valueAccessor)
3233
{
3334
_materializationContext = materializationContext;
3435
_valueAccessor = valueAccessor;
3536
EntityType = entityType;
37+
QueryTrackingBehavior = queryTrackingBehavior;
3638
}
3739

3840
/// <summary>
@@ -46,6 +48,11 @@ public DbContext Context
4648
/// </summary>
4749
public IEntityType EntityType { get; }
4850

51+
/// <summary>
52+
/// The query tracking behavior, or <see langword="null" /> if this materialization is not from a query.
53+
/// </summary>
54+
public QueryTrackingBehavior? QueryTrackingBehavior { get; }
55+
4956
/// <summary>
5057
/// Gets the property value for the property with the given name.
5158
/// </summary>

src/EFCore/Query/Internal/EntityMaterializerSource.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private static readonly ConstructorInfo MaterializationInterceptionDataConstruct
165165
{
166166
typeof(MaterializationContext),
167167
typeof(IEntityType),
168+
typeof(QueryTrackingBehavior?),
168169
typeof(Dictionary<IPropertyBase, (object, Func<MaterializationContext, object?>)>)
169170
})!;
170171

@@ -242,6 +243,7 @@ private static Expression CreateInterceptionMaterializeExpression(
242243
MaterializationInterceptionDataConstructor,
243244
materializationContextExpression,
244245
Expression.Constant(entityType),
246+
Expression.Constant(bindingInfo.QueryTrackingBehavior, typeof(QueryTrackingBehavior?)),
245247
accessorDictionaryVariable)),
246248
Expression.Assign(
247249
creatingResultVariable,

test/EFCore.Specification.Tests/MaterializationInterceptionTestBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public virtual void Intercept_query_materialization_for_empty_constructor(bool i
8383
{
8484
Assert.Same(context, data.Context);
8585
Assert.Same(data.Context.Model.FindEntityType(typeof(Book)), data.EntityType);
86+
Assert.Equal(QueryTrackingBehavior.TrackAll, data.QueryTrackingBehavior);
8687

8788
var idProperty = data.EntityType.FindProperty(nameof(Book.Id))!;
8889
var id = data.GetPropertyValue<Guid>(nameof(Book.Id))!;
@@ -189,6 +190,7 @@ public virtual void Intercept_query_materialization_for_full_constructor(bool in
189190
{
190191
Assert.Same(context, data.Context);
191192
Assert.Same(data.Context.Model.FindEntityType(typeof(Pamphlet)), data.EntityType);
193+
Assert.Equal(QueryTrackingBehavior.TrackAll, data.QueryTrackingBehavior);
192194

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

0 commit comments

Comments
 (0)