Skip to content

Conversation

@NgJason
Copy link

@NgJason NgJason commented Jul 4, 2025

TypeDescriptor.GetProperties incorrectly gets all properties for entityType, ignoring the property filtering set in OrmConfiguration.Conventions.GetEntityProperties

Imagine the code is set up as follows:

https://www.learndapper.com/relationships#dapper-one-to-many-relationships

The entry point of this bug is here:

var parentChildrenRelationships = this.DiscoverParentChildrenRelationships(entityType);

It calls TypeDescriptor.GetProperties

var parentChildrenPropGroups = TypeDescriptor.GetProperties(entityType)

which would return all properties for Category, including
public ICollection<Product> Products { get; set; }

The execution then leads the following lines / stack :

var childParentRelationships = this.DiscoverChildParentRelationships(childEntityType)

var entityColumnProperties = OrmConfiguration.Conventions.GetEntityProperties(entityType);

This line invokes

&& this.IsSimpleSqlType(propDesc.PropertyType));

which filters out all properties that are not IsSimpleSqlType

using the example provided earlier, this property is NOT returned:
public Category Category { get; set; }

causing the code to throw an error :

$"Unable to find any child-parent relationship for the child type '{childEntityType}' and the parent '{entityType}' when analyzing the navigation property '{parentChildrenNavigationProperty.Name}' on the parent entity.");

As observed, DiscoverParentChildren retrieves all properties , but DiscoverChildParentRelationships returns only the properties where IsSimpleSqlType == true.

I believe the parent fields should have the same filtering defined in OrmConfiguration.Conventions.GetEntityProperties, which is already extensible via overriding the virtual method.

TypeDescriptor.GetProperties incorrectly get all properties for entityType, ignoring properties filtering set in OrmConfiguration.Conventions.GetEntityProperties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant