示例#1
0
        protected override void Configure(Configuration cfg)
        {
            var persistenceModel = AutoMap.AssemblyOf <Product>(new AutomappingConfiguration())
                                   .Conventions.AddFromAssemblyOf <Conventions>();

            cfg.AddAutoMappings(persistenceModel);
        }
示例#2
0
        private static ISessionFactory Init(string cfgFile, string sessionKey, IDictionary <string, string> cfgProperties)
        {
            Configuration cfg = ConfigureNHibernate(cfgFile, cfgProperties);

            string instCode = sessionKey.Split('_')[0];
            AutoPersistenceModel autoPersistenceModel = AddMappingAssembliesTo(instCode, cfg);

            autoPersistenceModel.Conventions.Add <ClassMappingConvention>();
            autoPersistenceModel.Conventions.Add <ReferencesConvention>();
            autoPersistenceModel.Conventions.Add <EnumMappingConvention>();
            autoPersistenceModel.Conventions.Add <InstitutionCodePropertyConvention>();

            cfg.AddAutoMappings(autoPersistenceModel);

            // Add the Listeners
            var auditLogEvent = new AuditLogEventListener();

            cfg.SetListener(ListenerType.Merge, auditLogEvent);
            cfg.SetListener(ListenerType.Flush, auditLogEvent);
            cfg.SetListener(ListenerType.PreDelete, auditLogEvent);

            try
            {
                //var fluentCfg = FluentNHibernate.Cfg.Fluently.Configure(cfg)
                //    .Mappings(val => val.AutoMappings.Add(autoPersistenceModel));
                var factory = cfg.BuildSessionFactory();

                try
                {
                    SessionFactoryCreated?.Invoke(factory);
                }
                catch { }

                SessionFactories[instCode] = factory;

                return(factory);
            }
            catch (HibernateException ex)
            {
                throw new HibernateException("Cannot create session factory; " + ex.GetFullExceptionMessage());
            }
        }