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); }); }
public void ApplyMapping(Attribute attribute, System.Reflection.MemberInfo idProperty, Type entityType, NHibernate.Mapping.ByCode.IClassAttributesMapper mapper, MappingContext context) { mapper.Id(idProperty, m => m.Generator(Generators.Guid)); }