Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't look for CLR properties on property bag entity types #25809

Merged
merged 1 commit into from
Sep 1, 2021
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
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