Skip to content

Commit

Permalink
Don't look for CLR properties on property bag entity types
Browse files Browse the repository at this point in the history
Fixes #25485
Fixes #14267
  • Loading branch information
AndriySvyryd committed Sep 1, 2021
1 parent 9ad5a69 commit b820df4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ public virtual bool CanRemoveKey(ConfigurationSource configurationSource)
return null;
}

memberInfo ??= Metadata.ClrType.GetMembersInHierarchy(propertyName).FirstOrDefault();
memberInfo ??= Metadata.IsPropertyBag
? null
: Metadata.ClrType.GetMembersInHierarchy(propertyName).FirstOrDefault();

if (propertyType == null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/EFCore/Metadata/Internal/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,9 @@ public virtual IEnumerable<EntityType> GetEntityTypes()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual EntityType? FindEntityType(string name)
{
Check.DebugAssert(!string.IsNullOrEmpty(name), "name is null or empty");
return _entityTypes.TryGetValue(name, out var entityType)
=> !string.IsNullOrEmpty(name) && _entityTypes.TryGetValue(name, out var entityType)
? entityType
: null;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
1 change: 1 addition & 0 deletions test/EFCore.Tests/Metadata/Internal/ModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public void Can_get_entity_by_type()
Assert.Same(entityType, model.FindEntityType(typeof(Customer)));
Assert.Same(entityType, model.FindEntityType(typeof(Customer)));
Assert.Null(model.FindEntityType(typeof(string)));
Assert.Null(model.FindEntityType(typeof(IList<>).GetGenericArguments().Single()));
}

[ConditionalFact]
Expand Down
6 changes: 6 additions & 0 deletions test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,9 @@ public virtual void Can_add_shared_type_entity_type()
modelBuilder.SharedTypeEntity<Dictionary<string, object>>("Shared1", b =>
{
b.IndexerProperty<int>("Key");
b.Property<int>("Keys");
b.Property<byte[]>("Values");
b.Property<string>("Count");
b.HasKey("Key");
});

Expand All @@ -2087,6 +2090,9 @@ public virtual void Can_add_shared_type_entity_type()
Assert.NotNull(shared1);
Assert.True(shared1.HasSharedClrType);
Assert.Null(shared1.FindProperty("Id"));
Assert.Equal(typeof(int), shared1.FindProperty("Keys").ClrType);
Assert.Equal(typeof(byte[]), shared1.FindProperty("Values").ClrType);
Assert.Equal(typeof(string), shared1.FindProperty("Count").ClrType);

var shared2 = model.FindEntityType("Shared2");
Assert.NotNull(shared2);
Expand Down

0 comments on commit b820df4

Please sign in to comment.