Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ public static void IncludeJsonEntityReference<TIncludingEntity, TIncludedEntity>
TIncludingEntity entity,
Func<QueryContext, object[]?, JsonReaderData, TIncludedEntity> innerShaper,
Action<TIncludingEntity, TIncludedEntity> fixup,
bool trackingQuery)
bool performFixup)
where TIncludingEntity : class
where TIncludedEntity : class
{
Expand All @@ -1116,7 +1116,7 @@ public static void IncludeJsonEntityReference<TIncludingEntity, TIncludedEntity>

var included = innerShaper(queryContext, keyPropertyValues, jsonReaderData);

if (!trackingQuery)
if (performFixup)
{
fixup(entity, included);
}
Expand All @@ -1137,7 +1137,7 @@ public static void IncludeJsonEntityCollection<TIncludingEntity, TIncludedCollec
Func<QueryContext, object[]?, JsonReaderData, TIncludedCollectionElement> innerShaper,
Action<TIncludingEntity> getOrCreateCollectionObject,
Action<TIncludingEntity, TIncludedCollectionElement> fixup,
bool trackingQuery)
bool performFixup)
where TIncludingEntity : class
where TIncludedCollectionElement : class
{
Expand Down Expand Up @@ -1181,7 +1181,7 @@ public static void IncludeJsonEntityCollection<TIncludingEntity, TIncludedCollec
manager.CaptureState();
var resultElement = innerShaper(queryContext, newKeyPropertyValues, jsonReaderData);

if (!trackingQuery)
if (performFixup)
{
fixup(entity, resultElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
case JsonProjectionInfo jsonProjectionInfo:
{
if (_isTracking)
// Disallow tracking queries to project owned entities (but not complex types)
if (shaper.StructuralType is IEntityType && _isTracking)
{
// TODO: Update
throw new InvalidOperationException(CoreStrings.OwnedEntitiesCannotBeTrackedWithoutTheirOwner);
Expand Down Expand Up @@ -624,7 +625,8 @@ protected override Expression VisitExtension(Expression extensionExpression)

case QueryableJsonProjectionInfo queryableJsonEntityProjectionInfo:
{
if (_isTracking)
// Disallow tracking queries to project owned entities (but not complex types)
if (shaper.StructuralType is IEntityType && _isTracking)
{
throw new InvalidOperationException(CoreStrings.OwnedEntitiesCannotBeTrackedWithoutTheirOwner);
}
Expand Down Expand Up @@ -761,11 +763,6 @@ protected override Expression VisitExtension(Expression extensionExpression)
} collectionResult
when GetProjectionIndex(projectionBindingExpression) is JsonProjectionInfo jsonProjectionInfo:
{
if (_isTracking)
{
throw new InvalidOperationException(CoreStrings.OwnedEntitiesCannotBeTrackedWithoutTheirOwner);
}

var relatedStructuralType = relationship switch
{
IComplexProperty complexProperty => (ITypeBase)complexProperty.ComplexType,
Expand All @@ -774,6 +771,12 @@ when GetProjectionIndex(projectionBindingExpression) is JsonProjectionInfo jsonP
_ => throw new UnreachableException()
};

// Disallow tracking queries to project owned entities (but not complex types)
if (relatedStructuralType is IEntityType && _isTracking)
{
throw new InvalidOperationException(CoreStrings.OwnedEntitiesCannotBeTrackedWithoutTheirOwner);
}

// json entity collection at the root
var (jsonReaderDataVariable, keyValuesParameter) = JsonShapingPreProcess(
jsonProjectionInfo,
Expand Down Expand Up @@ -1709,6 +1712,11 @@ private Expression CreateJsonShapers(
inverseNavigation);

innerFixupMap[navigationJsonPropertyName] = fixup;

if (relatedStructuralType is IComplexType)
{
trackingInnerFixupMap[navigationJsonPropertyName] = fixup;
}
}
}

Expand Down Expand Up @@ -1778,7 +1786,9 @@ private Expression CreateJsonShapers(
shaperLambda,
GetOrCreateCollectionObjectLambda(declaringClrType, relationship),
fixup,
Constant(_isTracking));
// Perform fixup only for non-tracking queries - for tracking queries the change tracker does fixup.
// Note that for complex JSON types we also perform fixup, even for tracking queries.
Constant(!_isTracking || structuralType is IComplexType));

return declaringClrType.IsAssignableFrom(containerEntityExpression.Type)
? includeJsonEntityCollectionMethodCall
Expand All @@ -1796,7 +1806,9 @@ private Expression CreateJsonShapers(
includingEntityExpression,
shaperLambda,
fixup,
Constant(_isTracking));
// Perform fixup only for non-tracking queries - for tracking queries the change tracker does fixup.
// Note that for complex JSON types we also perform fixup, even for tracking queries.
Constant(!_isTracking || structuralType is IComplexType));

return declaringClrType.IsAssignableFrom(containerEntityExpression.Type)
? includeJsonEntityReferenceMethodCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ namespace Microsoft.EntityFrameworkCore.Query.Relationships.ComplexProperties;

public abstract class ComplexPropertiesCollectionTestBase<TFixture>(TFixture fixture)
: RelationshipsCollectionTestBase<TFixture>(fixture)
where TFixture : ComplexPropertiesFixtureBase, new()
{
// TODO: the following is temporary until change tracking is implemented for complex JSON types (#35962)
private readonly TrackingRewriter _trackingRewriter = new(QueryTrackingBehavior.NoTracking);

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
{
var rewritten = _trackingRewriter.Visit(serverQueryExpression);

return rewritten;
}
}
where TFixture : ComplexPropertiesFixtureBase, new();
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ namespace Microsoft.EntityFrameworkCore.Query.Relationships.ComplexProperties;

public abstract class ComplexPropertiesMiscellaneousTestBase<TFixture>(TFixture fixture)
: RelationshipsMiscellaneousTestBase<TFixture>(fixture)
where TFixture : ComplexPropertiesFixtureBase, new()
{
// TODO: the following is temporary until change tracking is implemented for complex JSON types (#35962)
private readonly TrackingRewriter _trackingRewriter = new(QueryTrackingBehavior.NoTracking);

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
{
var rewritten = _trackingRewriter.Visit(serverQueryExpression);

return rewritten;
}
}
where TFixture : ComplexPropertiesFixtureBase, new();
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ namespace Microsoft.EntityFrameworkCore.Query.Relationships.ComplexProperties;

public abstract class ComplexPropertiesProjectionTestBase<TFixture>(TFixture fixture)
: RelationshipsProjectionTestBase<TFixture>(fixture)
where TFixture : ComplexPropertiesFixtureBase, new()
{
// TODO: the following is temporary until change tracking is implemented for complex JSON types (#35962)
private readonly TrackingRewriter _trackingRewriter = new(QueryTrackingBehavior.NoTracking);

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
{
var rewritten = _trackingRewriter.Visit(serverQueryExpression);

return rewritten;
}
}
where TFixture : ComplexPropertiesFixtureBase, new();
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ namespace Microsoft.EntityFrameworkCore.Query.Relationships.ComplexProperties;

public abstract class ComplexPropertiesSetOperationsTestBase<TFixture>(TFixture fixture)
: RelationshipsSetOperationsTestBase<TFixture>(fixture)
where TFixture : ComplexPropertiesFixtureBase, new()
{
// TODO: the following is temporary until change tracking is implemented for complex JSON types (#35962)
private readonly TrackingRewriter _trackingRewriter = new(QueryTrackingBehavior.NoTracking);

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
{
var rewritten = _trackingRewriter.Visit(serverQueryExpression);

return rewritten;
}
}
where TFixture : ComplexPropertiesFixtureBase, new();
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,4 @@ await AssertQuery(
ss => ss.Set<RootEntity>().Where(e => e.RequiredRelated.NestedCollection == nestedCollection),
ss => ss.Set<RootEntity>().Where(e => e.RequiredRelated.NestedCollection.SequenceEqual(nestedCollection)));
}

// TODO: the following is temporary until change tracking is implemented for complex JSON types (#35962)
private readonly TrackingRewriter _trackingRewriter = new(QueryTrackingBehavior.NoTracking);

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
{
var rewritten = _trackingRewriter.Visit(serverQueryExpression);

return rewritten;
}
}