Get all classes that implement Classmapping<>

Asked

Viewed 21 times

-1

List<Type> entityMappings = new List<Type>();
IEnumerable<Type> allTypesInThisAssembly = Assembly.GetExecutingAssembly().GetTypes();

foreach (Type type in allTypesInThisAssembly)
{
    if (type.GetInterface(typeof(ClassMapping<>).Name.ToString()) != null)
    {
        entityMappings.Add(type);
    }
}

I tried that way, but it didn’t work.

  • Explain your problem better, what exactly you’re trying to do and why?

  • Sorry it took me so long to respond. Basically doing the configuration to add a Nhibernate Singleton, and I was having trouble with addMapping, and for that, I needed Nhibernate to have an example class. that in Example of my code I used Student Map. But after a lot of research, I was able to solve.

  • 1

    So, that’s what you should have written in your question....

1 answer

0

I was able to solve it this way:

 services.AddSingleton<ISessionFactory>((serviceProvider) =>
        {
            var settings = configuration.GetSection("NHibernateConfig")
                                    .GetChildren()
                                    .ToDictionary(x => x.Key, x => x.Value);

            var nhConfiguration = new Configuration();
            nhConfiguration.AddProperties(settings);

            var mapper = new ModelMapper();

            mapper.AddMappings(typeof(AlunoMap).Assembly.ExportedTypes);
            HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
            
            mappings.autoimport = false;
            nhConfiguration.AddMapping(mappings);

            return nhConfiguration.BuildSessionFactory();
        });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.