Skip to content

Commit 9496321

Browse files
committed
Use MetadataToken when searching for IProperty for a specific MemberInfo
* Using equality comparison yields false when the property comes from a base class because the reflected type is taken in consideration as well
1 parent 75664b7 commit 9496321

File tree

14 files changed

+2287
-6
lines changed

14 files changed

+2287
-6
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
5-
<VersionPrefix>4.4.1</VersionPrefix>
5+
<VersionPrefix>4.4.2</VersionPrefix>
66
<Authors>Pawel Gerr</Authors>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageProjectUrl>https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore</PackageProjectUrl>

src/Thinktecture.EntityFrameworkCore.BulkOperations/Extensions/BulkOperationsCollectionExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ internal static IReadOnlyList<PropertyWithNavigations> ConvertToEntityProperties
4646

4747
private static IProperty? FindProperty(IEntityType entityType, MemberInfo memberInfo)
4848
{
49-
return entityType.GetProperties().FirstOrDefault(property => property.PropertyInfo == memberInfo || property.FieldInfo == memberInfo);
49+
return entityType.GetProperties().FirstOrDefault(property => property.PropertyInfo?.MetadataToken == memberInfo.MetadataToken
50+
|| property.FieldInfo?.MetadataToken == memberInfo.MetadataToken);
5051
}
5152

5253
private static INavigation? FindOwnedProperty(

tests/Thinktecture.EntityFrameworkCore.SqlServer.Tests/EntityFrameworkCore/BulkOperations/SqlServerBulkOperationExecutorTests/BulkUpdateAsync.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,25 @@ public async Task Should_update_entity_with_auto_increment_having_custom_propert
325325
Name = "Name"
326326
});
327327
}
328+
329+
[Fact]
330+
public async Task Should_update_property_of_base_class()
331+
{
332+
var entity = new TestEntityWithBaseClass { Id = new Guid("3D3AECE7-3B5A-48C6-9C8C-CAB7FFE2120D"), Name = "Initial" };
333+
ArrangeDbContext.Add(entity);
334+
await ArrangeDbContext.SaveChangesAsync();
335+
336+
entity.Name = "changed";
337+
338+
var affectedRows = await SUT.BulkUpdateAsync(new[] { entity }, new SqlServerBulkUpdateOptions
339+
{
340+
PropertiesToUpdate = IEntityPropertiesProvider.Include<TestEntityWithBaseClass>(e => e.Name)
341+
});
342+
343+
affectedRows.Should().Be(1);
344+
345+
var loadedEntity = await AssertDbContext.TestEntitiesWithBaseClass.FirstOrDefaultAsync();
346+
loadedEntity.Should().NotBeNull();
347+
loadedEntity!.Name.Should().Be("changed");
348+
}
328349
}

0 commit comments

Comments
 (0)