Esempio n. 1
0
        public static ISessionFactory GetSessionFactory()
        {
            if (_isf != null)
            {
                return(_isf);
            }

            var cfg = new StoreConfiguration();

            var sessionFactory = Fluently.Configure()
                                 .Database(MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(
                                               "Server=localhost; Database=Test; Trusted_Connection=true; MultipleActiveResultSets=true")
                                           )

                                 .Cache(c => c.ProviderClass(typeof(NHibernate.Caches.Redis.RedisProvider).AssemblyQualifiedName)
                                        .UseQueryCache().UseSecondLevelCache())

                                 .Mappings(m =>
                                           m.AutoMappings
                                           .Add(AutoMap.AssemblyOf <Person>(cfg)
                                                .Conventions.Add <ReferenceConvention>()
                                                .Conventions.Add <HasManyConvention>()
                                                .Override <Country>(x => x.HasMany(y => y.NaturalBorns).KeyColumn("CountryBorned_CountryId"))
                                                )
                                           )
                                 .BuildSessionFactory();


            _isf = sessionFactory;

            return(_isf);
        }
        public static ISessionFactory GetSessionFactory()
        {
            if (_isf != null) return _isf;

            var cfg = new StoreConfiguration();

            var sessionFactory = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(
                    "Server=localhost; Database=Test; Trusted_Connection=true; MultipleActiveResultSets=true")
                    )

                .Cache(c => c.ProviderClass(typeof(NHibernate.Caches.Redis.RedisProvider).AssemblyQualifiedName)
                .UseQueryCache().UseSecondLevelCache())

                .Mappings(m =>
                m.AutoMappings
                    .Add(AutoMap.AssemblyOf<Person>(cfg)
                    .Conventions.Add<ReferenceConvention>()
                    .Conventions.Add<HasManyConvention>()
                    .Override<Country>(x => x.HasMany(y => y.NaturalBorns).KeyColumn("CountryBorned_CountryId"))
                    )
                )
                .BuildSessionFactory();

            _isf = sessionFactory;

            return _isf;
        }