Beispiel #1
0
        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);
            });
        }
Beispiel #2
0
        void Mapper_BeforeMapClass(
            NHibernate.Mapping.ByCode.IModelInspector modelInspector,
            System.Type type,
            NHibernate.Mapping.ByCode.IClassAttributesMapper classCustomizer
            )
        {
            if (this.UseCache)
            {
                classCustomizer.Cache(cacheMapping => cacheMapping.Usage(NHibernate.Mapping.ByCode.CacheUsage.ReadWrite));
            }


            string fullName = type.FullName; // example: AspNetCoreExample.Ddd.IdentityDomain.ApplicationUser

            var(schemaName, tableName) = fullName.GetTableMapping();


            classCustomizer.Schema(schemaName);
            classCustomizer.Table(tableName);

            classCustomizer.Lazy(true);


            // If this needs to be turned on..
            classCustomizer.DynamicUpdate(true);
            // ..this needs to be turned on too.
            classCustomizer.SelectBeforeUpdate(true);
            // As not doing so, could cause inconsistent update: http://stackoverflow.com/questions/13954882/nhibernate-dynamic-update-disadvantages


            CustomizeIdPrimaryKey(type, classCustomizer, schemaName, tableName);
            CustomizeEnumPrimaryKey(type, classCustomizer);
        }