Fix DiscoverParentChildRelationship properties list #210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
FastCrud/Dapper.FastCrud/Mappings/AutoGeneratedEntityMapping.cs
Line 52 in a5941a1
It calls TypeDescriptor.GetProperties
FastCrud/Dapper.FastCrud/Mappings/AutoGeneratedEntityMapping.cs
Line 122 in a5941a1
which would return all properties for Category, including
public ICollection<Product> Products { get; set; }The execution then leads the following lines / stack :
FastCrud/Dapper.FastCrud/Mappings/AutoGeneratedEntityMapping.cs
Line 167 in a5941a1
FastCrud/Dapper.FastCrud/Mappings/AutoGeneratedEntityMapping.cs
Line 71 in a5941a1
This line invokes
FastCrud/Dapper.FastCrud/Configuration/OrmConventions.cs
Line 169 in a5941a1
which filters out all properties that are not
IsSimpleSqlTypeusing the example provided earlier, this property is NOT returned:
public Category Category { get; set; }causing the code to throw an error :
FastCrud/Dapper.FastCrud/Mappings/AutoGeneratedEntityMapping.cs
Line 181 in a5941a1
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.