Exemple #1
0
        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));
        }
Exemple #2
0
        void Mapper_BeforeMapBag(
            NHibernate.Mapping.ByCode.IModelInspector modelInspector,
            NHibernate.Mapping.ByCode.PropertyPath propertyPath,
            NHibernate.Mapping.ByCode.IBagPropertiesMapper bagPropertiesCustomizer
            )
        {
            /*
             * class Person
             * {
             *      IList<Hobby> Hobbies
             * }
             *
             *
             */

            // this gets the person table. lowercase name in postgres.
            string parentEntity = propertyPath.LocalMember.DeclaringType.Name.ToLowercaseNamingConvention();
            string foreignKey   = parentEntity + "_fk";

            bagPropertiesCustomizer.Key(keyMapping => keyMapping.Column(foreignKey));


            // http://www.ienablemuch.com/2014/10/inverse-cascade-variations-on-nhibernate.html
            // best persistence approach: Inverse+CascadeAll
            bagPropertiesCustomizer.Inverse(true);
            bagPropertiesCustomizer.Cascade(NHibernate.Mapping.ByCode.Cascade.All | NHibernate.Mapping.ByCode.Cascade.DeleteOrphans);

            bagPropertiesCustomizer.Lazy(NHibernate.Mapping.ByCode.CollectionLazy.Extra);


            if (this.UseCache)
            {
                bagPropertiesCustomizer.Cache(
                    cacheMapping => cacheMapping.Usage(NHibernate.Mapping.ByCode.CacheUsage.ReadWrite)
                    );
            }
        }