views:

78

answers:

0

I am trying to pass strings to my build Factory function. One string would be the path and name of the EO.dll. The other would be the path and name of the Map.dll.

When I was hard coding the class name this worked for me.

                        //// this was the origonal
                        //m.HbmMappings.AddFromAssemblyOf<AddressEO>
                        //m.FluentMappings.AddFromAssemblyOf<AddressEOMap>()
                        //            .AddFromAssemblyOf<AddressEO>();

Here I am trying to make it more generic for multiple DB’s.

public ISessionFactory GetFactoryByConfigFile(string configFname, string eoFullDll, string mapFullDll)        
    {

        //Make sure files exist
        if (!File.Exists(configFname))
            throw new Exception("GetFactoryByConfigFile, configFname does not exist>" + configFname + "<");
        if (!File.Exists(eoFullDll))
            throw new Exception("GetFactoryByConfigFile, eoFullDll does not exist>" + eoFullDll + "<");
        if (!File.Exists(mapFullDll))
            throw new Exception("GetFactoryByConfigFile, mapFullDll does not exist>" + mapFullDll + "<");

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

        Assembly EoAssembly = Assembly.LoadFrom(eoFullDll );  //"D:/MyPath/Project.DBName.EO.DLL"
        Assembly MapAssembly = Assembly.LoadFrom(mapFullDll); //"D:/MyPath/Project.DBName.Map.DLL"

        //Type EOType = EoAssembly.GetType("AddressEO");
        //Type MapType = MapAssembly.GetType("AddressEOMap");

        configuration = configuration.Configure(path + NHibernateConfigFileName);
        FluentConfiguration fluent = Fluently.Configure(configuration);
        ISessionFactory localFactory =
            fluent.Mappings(
                m =>
                    {

                        //// this was the origonal
                        //m.HbmMappings.AddFromAssemblyOf<AddressEO>
                        //m.FluentMappings.AddFromAssemblyOf<AddressEOMap>()
                        //            .AddFromAssemblyOf<AddressEO>();

                        //// first try
                        //m.HbmMappings.AddFromAssembly(EOType);
                        //m.FluentMappings.AddFromAssembly(MapType);

                        //// Second try
                        //m.HbmMappings.AddFromAssembly(EoAssembly);
                        //m.FluentMappings.AddFromAssembly(MapAssembly)
                        //   .AddFromAssembly(EoAssembly);


                        //// third try
                        //m.HbmMappings.AddFromAssemblyOf<EOType>();
                        //m.FluentMappings.AddFromAssemblyOf<MapType>()
                        //            .AddFromAssemblyOf<EOType>();

                        // fourth try
                        m.HbmMappings.AddClasses(EoAssembly.GetTypes());
                        m.FluentMappings.AddFromAssembly(MapAssembly)
                            .AddFromAssembly(EoAssembly);


                    }
            )
            .BuildSessionFactory();

        return localFactory;
    }

Any help would be greatly appreciated.