static ISessionFactory CreateSessionFactory(string connectionString)
        {
            #region Please implement the method to pass the test

            /*
             * We use *FluentNHiberate* package to configure NHibernate. In order
             * to do query, we should get a `ISession` object, which holds the
             * connection to database. The `ISession` object is created by a
             * `ISessionFactory` so `ISessionFactory` should be created first.
             */

            var mappingCfg = new TypeSpecificAutomappingConfiguration();

            return(Fluently.Configure()
                   .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString))
                   .Mappings(m => m.AutoMappings.Add(AutoMap.Assembly(Assembly.GetExecutingAssembly(), mappingCfg).UseOverridesFromAssembly(Assembly.GetExecutingAssembly())))
                   .BuildSessionFactory());

            #endregion
        }
Exemple #2
0
        ISessionFactory CreateSessionFactory(string connectionString)
        {
            MsSqlConfiguration config = MsSqlConfiguration.MsSql2012
                                        .ConnectionString(connectionString)
                                        .ShowSql()
                                        .FormatSql();

            Console.SetOut(outputCache);

            IAutomappingConfiguration mappingConfig = new TypeSpecificAutomappingConfiguration();
            Assembly currentAssembly = Assembly.GetExecutingAssembly();

            return(Fluently
                   .Configure()
                   .Database(config)
                   .Mappings(
                       m => m.AutoMappings.Add(
                           AutoMap
                           .Assembly(currentAssembly, mappingConfig)
                           .UseOverridesFromAssembly(currentAssembly)))
                   .BuildSessionFactory());
        }