Fluently.Configure without explicitly entering types.

Posted by user86431 on Stack Overflow See other posts from Stack Overflow or by user86431
Published on 2010-04-12T14:35:09Z Indexed on 2010/04/12 14:42 UTC
Read the original article Hit count: 228

Filed under:

I'm trying to take my fluent mapping past the basic stuff that I've found here:

http://wiki.fluentnhibernate.org/Fluent_configuration

Where they explicitly add each type like this:

ISessionFactory localFactory =
                Fluently.Configure()
                    .Database( ObjectFactory.GetInstance<SybaseConfiguration>().GetSybaseDialect( "BLAH" ) )
                    .Mappings( m =>
                    {
                        m.HbmMappings
                            .AddFromAssemblyOf<StudTestEO>();
                        m.FluentMappings
                            .AddFromAssemblyOf<StudTestEO>()
                            .AddFromAssemblyOf<StudTestEOMap>();
                    } )
                    .BuildSessionFactory();  .BuildSessionFactory();

and trying to be able to take the assembly, get a list of it's types and pass that in instead

kindf like this

string FullEoAssemblyFName = webAccessHdl.GetMapPath(EoAssemblyFName);
            string FullMapAssemblyFName = webAccessHdl.GetMapPath(MapAssemblyFName);
            string FullConfigFileName = webAccessHdl.GetMapPath("~/" + NHibernateConfigFileName);

            if (!File.Exists(FullEoAssemblyFName))
                throw new Exception("GetFactoryByConfigFile, EoAssemblyFName does not exist>" + FullEoAssemblyFName + "<");
            if (!File.Exists(FullMapAssemblyFName))
                throw new Exception("GetFactoryByConfigFile, MapAssemblyFName does not exist>" + FullMapAssemblyFName + "<");
            if (!File.Exists(FullConfigFileName))
                throw new Exception("GetFactoryByConfigFile, ConfigFile does not exist>" + FullConfigFileName + "<");

            Configuration configuration = new Configuration();

            Assembly EoAssembly = Assembly.LoadFrom(webAccessHdl.GetMapPath(EoAssemblyFName));
            Assembly MapAssembly = Assembly.LoadFrom(webAccessHdl.GetMapPath(MapAssemblyFName));

            Type[] EoType = EoAssembly.GetTypes();
            Type[] MapType = MapAssembly.GetTypes();
ISessionFactory localFactory =
                fluent.Mappings(
                    m =>
                        {

                            // how do i add all the types from type array here?
                            m.FluentMappings.Add(MapAssembly).AddFromAssembly(EoAssembly);


                        }
                )
                .BuildSessionFactory();

To get it to load the types genericly instead of explicitly..

has anyone done this, or see any good links to articles I should look at?

Thanks,

E-

© Stack Overflow or respective owner

Related posts about fluent-nhibernate