protected override void AdjustConfiguration(NHibernate.Cfg.Configuration cfg)
 {
     //XmlConfigurator.Configure();
     cfg.Cache(x =>
                   {
                       x.UseQueryCache = true;
                       x.Provider<HashtableCacheProvider>();
                   });
 }
Esempio n. 2
0
        public void ApplyMapping(Attribute attribute, Type type, NHibernate.Mapping.ByCode.IClassAttributesMapper mapper, MappingContext context)
        {
            var cacheAttr = (CacheAttribute)attribute;

            mapper.Cache(m =>
            {
                m.Usage(GetNHibernateCacheUsage(cacheAttr));
                m.Include(GetNHibernateCacheInclude(cacheAttr));

                if (!String.IsNullOrEmpty(cacheAttr.Region))
                {
                    m.Region(cacheAttr.Region);
                }
            });
        }
        static void mapper_BeforeMapClass(NHibernate.Mapping.ByCode.IModelInspector modelInspector,
            System.Type type,
            NHibernate.Mapping.ByCode.IClassAttributesMapper classCustomizer)
        {

            classCustomizer.Cache(cacheMapping => cacheMapping.Usage(NHibernate.Mapping.ByCode.CacheUsage.ReadWrite));

            string fullName = type.FullName; // example: Domain.TheProduction+Product

            string[] fullNameSplit = fullName.Split('+');

            string className = fullNameSplit[1];

            // Last() skips the other namespace(s)
            string schemaDomainName = fullNameSplit[0].Split('.').Last();

            string schemaName = schemaDomainName.Substring(0, schemaDomainName.Length - "Domain".Length); 

            string sqlServerFullName = schemaName + "." + className;
            classCustomizer.Table(sqlServerFullName);

            System.Reflection.MemberInfo mi = type.GetMember(className + "Id",
                System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)[0];

            classCustomizer.Id(mi,
                idMapper =>
                {
                    idMapper.Column(className + "Id");
                    idMapper.Generator(NHibernate.Mapping.ByCode.Generators.Identity);
                });


        }
        static void mapper_BeforeMapBag(
            NHibernate.Mapping.ByCode.IModelInspector modelInspector, 
            NHibernate.Mapping.ByCode.PropertyPath member, 
            NHibernate.Mapping.ByCode.IBagPropertiesMapper propertyCustomizer)
        {

            /*
             * class Person
             * {
             *      IList<Hobby> Hobbies
             * }
             * 
             * 
             */

            string parentEntity = member.LocalMember.DeclaringType.Name; // this gets the Person
            string foreignKey = parentEntity + "Id";            
            propertyCustomizer.Key(keyMapping => keyMapping.Column(foreignKey));


            // http://www.ienablemuch.com/2014/10/inverse-cascade-variations-on-nhibernate.html
            // best persistence approach: Inverse+CascadeAll 
            propertyCustomizer.Inverse(true);
            propertyCustomizer.Cascade(NHibernate.Mapping.ByCode.Cascade.All);
            propertyCustomizer.Cache(cacheMapping => cacheMapping.Usage(NHibernate.Mapping.ByCode.CacheUsage.ReadWrite));
        }
Esempio n. 5
0
        protected virtual void RegisterProperties(NHibernate.Cfg.Configuration configuration)
        {
            configuration.Proxy(p => p.ProxyFactoryFactory<ComponentProxyFactoryFactory>());
            configuration.DataBaseIntegration(db =>
            {
                db.Dialect<MsSql2005Dialect>();
                db.Driver<SqlClientDriver>();
                //db.ConnectionStringName = "ConnectionString";
                db.ConnectionString = Common.Constants.AppConfig.ConnectionString;
                db.BatchSize = 10;
            });
            configuration.CurrentSessionContext<ThreadLocalConversationalSessionContext>();

            configuration.Cache(cp =>
            {
                cp.UseQueryCache = true;
                cp.Provider<SysCacheProvider>();
            });
        }