schotime / NPoco

Simple microORM that maps the results of a query onto a POCO object. Project based on Schotime's branch of PetaPoco
Apache License 2.0
848 stars 302 forks source link

Implementation of a Max Depth for member scanning #638

Open ilya-at-prettyneat opened 3 years ago

ilya-at-prettyneat commented 3 years ago

Adds the DepthLimit attribute and the ability to set depth limits in the Fluent Config. If the DepthLimit is set for a specific column, that column will not explore all the possible branches but rather stop after computing all the paths with a maximum distance of N from its source.

As an example, if you set it like:

c.Column(m => m.MyProp).Reference( m => m.Id, ReferenceType.OneToOne).LimitMappingDepth(2)

That means that it will explore all the members in MyProp, if it finds child members in MyChildProp it will explore those too, but then it will not go further away from MyProp (depth 2 reached).

The loop protection is still valid and in place, but this adds to it and is invaluable if you have data structures with several foreign keys that can branch, as the flattening of that tree can lead to hundreds of thousands of possible paths.

Use as a typical NPoco column attribute or at the end of a Column or Many declaration in fluent config.