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

Multiple IncludeTypes in FluentMappingConfiguration #630

Open ashansen opened 3 years ago

ashansen commented 3 years ago

Hi. We have an issue where we have multiple Mappings/Types to include, and they weren't getting bound with [schema].[tablename] but only [tablename].

It looks like there might be an issue inside FindTypes in FluentMappingConfiguration:

 private static IEnumerable<Type> FindTypes(ConventionScannerSettings scannerSettings)
        {
            if (scannerSettings.TheCallingAssembly)
                scannerSettings.Assemblies.Add(FindTheCallingAssembly());

            var types = scannerSettings.Assemblies
                .SelectMany(x => x.GetExportedTypes())
                .Where(x => scannerSettings.IncludeTypes.All(y => y.Invoke(x)))
                .Where(x => scannerSettings.MapNestedTypesWhen(x) || !x.IsNested)
                .Where(x => !typeof (Map<>).IsAssignableFrom(x) && !typeof (Mappings).IsAssignableFrom(x));
            return types;
        }

As it looks the classes should be in all settings, instead of just existing in one. scannerSettings.IncludeTypes.All(y => y.Invoke(x)))

I ran some quick test and if changing to Any it looks like it'll fix my issue, but I'm unsure if there's other side-effects elsewhere in the bindings, that I'm not aware of/have experienced?

schotime commented 3 years ago

Hi, Thanks for the issue. Yeh it looks like there should've only been one IncludeTypes but somehow we ended up with the ability to add multiple. The work around is to only call IncludeTypes once and then do the logic inside of the one Func. Changing to an Any is possible too. I'll have to think about it, but yeh, its a simple workaround. Cheers