AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

Avoid circular reference when mapping unmapped types #125

Closed Tasteful closed 5 years ago

Tasteful commented 5 years ago

When using EF/EFCore and have an entity that have references to the parent (you should avoid it) the call to ResolveTypeMap will go into an circular lookup.

With this changes the logic to see if IsMatch is changed to only see if the source/dest is of collection types and in that case we try to create the expression to use. During creation of the expression we can call the ResolveTypeMap (without going into the circular lookup), and if we not get any equivalent mapping we find the next IObjectMapper that can handle the source/dest type and if no other is found we will fallback into the CollectionMapper (that was the only fallback mapper before this change).

https://github.com/AutoMapper/AutoMapper.Collection.EFCore/issues/13

TylerCarlson1 commented 5 years ago

I get the idea and it looks fairly sound, but I'll have to give it a lot more thought about possible scenarios.