Skip to content

Commit

Permalink
InMemory: Read nullable value for derived properties
Browse files Browse the repository at this point in the history
So that when that property is being read outside of entity materialization, we get null value rather than default of non-nullable type

Resolves #25735
  • Loading branch information
smitpatel committed Sep 10, 2021
1 parent 50daaa1 commit 9f6bc2a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ public InMemoryQueryExpression(IEntityType entityType)

foreach (var property in derivedEntityType.GetDeclaredProperties())
{
// We read nullable value from property of derived type since it could be null.
var typeToRead = property.ClrType.MakeNullable();
var propertyExpression = Condition(
entityCheck,
CreateReadValueExpression(property.ClrType, property.GetIndex(), property),
Default(property.ClrType));
CreateReadValueExpression(typeToRead, property.GetIndex(), property),
Default(typeToRead));

selectorExpressions.Add(propertyExpression);
var readExpression = CreateReadValueExpression(property.ClrType, selectorExpressions.Count - 1, property);
var readExpression = CreateReadValueExpression(propertyExpression.Type, selectorExpressions.Count - 1, property);
propertyExpressionsMap[property] = readExpression;
_projectionMappingExpressions.Add(readExpression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,5 @@ public override async Task Projecting_some_properties_as_well_as_correlated_coll

Assert.Equal(InMemoryStrings.DistinctOnSubqueryNotSupported, message);
}

[ConditionalTheory(Skip = "Issue #25735")]
public override Task Project_navigation_defined_on_derived_from_entity_with_inheritance_using_soft_cast(bool async)
{
return base.Project_navigation_defined_on_derived_from_entity_with_inheritance_using_soft_cast(async);
}
}
}

0 comments on commit 9f6bc2a

Please sign in to comment.