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

Object materialization duplicated when using IncludeMany #654

Open enrico-padovani opened 2 years ago

enrico-padovani commented 2 years ago

Hi,

I'm facing an issue where using IncludeMany.

When there are more childrens for the main entity, the query composed repeats the main entity Id.

This causes the object with the same repeated id to be materialized multiple times.

If I order the main entity by the id column, the problem is fixed but this is not convenient because we need to have another order by after the object materialization.

NPoco Version 5.3.2 .NET 6

enrico-padovani commented 2 years ago

I found this old issue #506 that seems to be the same problem.

Any advice how to solve it?

schotime commented 2 years ago

This would have to be fundamentally changed so that it used a Dictionary instead of an optimized list. Definitely a major version thing.

enrico-padovani commented 2 years ago

I don't know much about NPoco internals, but could it be possible to use the defined primary key over the entity in order to check if the object has already been added to the list?

If no PK is defined fall back to object equality.