protected override void OnBeforeMapClass(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) { classCustomizer.DynamicInsert(DynamicInsert); classCustomizer.DynamicUpdate(DynamicUpdate); classCustomizer.Table(GetTableName(modelInspector, type)); classCustomizer.Id( m => { m.Column(GetKeyColumnName(modelInspector, type, false)); m.Generator(Generators.HighLow); }); if (modelInspector.IsTablePerClassHierarchy(type)) { classCustomizer.Discriminator(m => m.Column(GetDiscriminatorColumnName(modelInspector, type))); classCustomizer.DiscriminatorValue(GetDiscriminatorValue(modelInspector, type)); } MemberInfo[] versionProperties = VersionProperties(modelInspector, type).ToArray(); if (versionProperties.Length == 1) { classCustomizer.Version(versionProperties[0], m => m.Column(GetVersionColumnName(modelInspector, type))); } }
void ApplyClassConvention(IModelInspector mi, Type type, IClassAttributesMapper map) { if (!sagaEntities.Contains(type)) { map.Id(idMapper => idMapper.Generator(Generators.GuidComb)); } else { map.Id(idMapper => idMapper.Generator(Generators.Assigned)); } var rowVersionProperty = type.GetProperties() .Where(HasAttribute <RowVersionAttribute>) .FirstOrDefault(); if (rowVersionProperty != null) { map.Version(rowVersionProperty, mapper => { mapper.Generated(VersionGeneration.Never); if (rowVersionProperty.PropertyType == typeof(DateTime)) { mapper.Type(new TimestampType()); } if (rowVersionProperty.PropertyType == typeof(byte[])) { mapper.Type(new BinaryBlobType()); mapper.Generated(VersionGeneration.Always); mapper.UnsavedValue(null); mapper.Column(cm => { cm.NotNullable(false); cm.SqlType(NHibernateUtil.Timestamp.Name); }); } }); } var tableAttribute = GetAttribute <TableNameAttribute>(type); if (tableAttribute != null) { map.Table(tableAttribute.TableName); if (!String.IsNullOrEmpty(tableAttribute.Schema)) { map.Schema(tableAttribute.Schema); } return; } var namingConvention = tableNamingConvention(type); map.Table(namingConvention); }
private static void MapClass(IModelInspector modelinspector, Type type, IClassAttributesMapper @class) { if (typeof(Entity).IsAssignableFrom(type)) { @class.Id(type.GetProperty("Id"), id => { id.Column(type.Name + "Id"); id.Generator(Generators.GuidComb); id.UnsavedValue(Guid.Empty); }); @class.Version(type.GetProperty("Version"), version => {}); } }
void ApplyClassConvention(IModelInspector mi, Type type, IClassAttributesMapper map) { if (!_sagaEntities.Contains(type)) { map.Id(idMapper => idMapper.Generator(Generators.GuidComb)); } else { map.Id(idMapper => idMapper.Generator(Generators.Assigned)); } var tableAttribute = GetAttribute <TableNameAttribute>(type); var rowVersionProperty = type.GetProperties() .Where(HasAttribute <RowVersionAttribute>) .FirstOrDefault(); if (rowVersionProperty != null) { map.Version(rowVersionProperty, mapper => mapper.Generated(VersionGeneration.Always)); } if (tableAttribute != null) { map.Table(tableAttribute.TableName); if (!String.IsNullOrEmpty(tableAttribute.Schema)) { map.Schema(tableAttribute.Schema); } return; } //if the type is nested use the name of the parent if (type.DeclaringType != null) { if (typeof(IContainSagaData).IsAssignableFrom(type)) { map.Table(type.DeclaringType.Name); } else { map.Table(type.DeclaringType.Name + "_" + type.Name); } } }
private void MapClass(IModelInspector modelInspector, Type classType, IClassAttributesMapper mapper) { Type entityType = classType.UnderlyingSystemType; string schemaName = namingEngine.ToSchemaName(entityType) ?? mapper.GetSchema(); string tableName = namingEngine.ToTableName(entityType); var idProperty = modelInspector.GetIdentifierMember(entityType); var versionProperty = modelInspector.GetVersionMember(entityType); string primaryKeyColumnName = namingEngine.ToPrimaryKeyColumnName(entityType, idProperty); // Mapping mapper.Schema(schemaName); mapper.Table(tableName); mapper.Id(id => id.Column(primaryKeyColumnName)); // Version mapping if (versionProperty != null) { string versionColumnName = namingEngine.ToColumnName(versionProperty); mapper.Version(versionProperty, m => m.Column(versionColumnName)); } }
/// <summary> /// Maps a property according the naming conventions configuration /// </summary> /// <param name="modelInspector">The model inspector</param> /// <param name="property">The class type</param> /// <param name="mapper">The class mapper</param> private void MapClass(IModelInspector modelInspector, Type classType, IClassAttributesMapper mapper) { Type entityType = classType.UnderlyingSystemType; string schemaName = namingEngine.ToSchemaName(entityType) ?? mapper.GetSchema(); string tableName = namingEngine.ToTableName(entityType); var idProperty = modelInspector.GetIdentifierMember(entityType); var versionProperty = modelInspector.GetVersionMember(entityType); string primaryKeyColumnName = namingEngine.ToPrimaryKeyColumnName(entityType, idProperty); // Mapping mapper.Schema(schemaName); mapper.Table(tableName); mapper.Id(id => id.Column(primaryKeyColumnName)); // Version mapping if (versionProperty != null) { string versionColumnName = namingEngine.ToColumnName(versionProperty); mapper.Version(versionProperty, m => m.Column(versionColumnName)); } }
private void MapVersion(IModelInspector modelinspector, Type type, IClassAttributesMapper classCustomizer) { foreach (var member in type.GetMembers().Where(member => Mapper.ModelInspector.IsVersion(member))) { classCustomizer.Version(member, vm => vm.Type((IVersionType) NHibernateUtil.GuessType(member.GetPropertyOrFieldType()))); } }
protected override void OnBeforeMapClass(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) { classCustomizer.DynamicInsert(DynamicInsert); classCustomizer.DynamicUpdate(DynamicUpdate); classCustomizer.Table(GetTableName(modelInspector, type)); classCustomizer.Id( m => { m.Column(GetKeyColumnName(modelInspector, type, false)); m.Generator(Generators.HighLow); }); if (modelInspector.IsTablePerClassHierarchy(type)) { classCustomizer.Discriminator(m => m.Column(GetDiscriminatorColumnName(modelInspector, type))); classCustomizer.DiscriminatorValue(GetDiscriminatorValue(modelInspector, type)); } MemberInfo[] versionProperties = VersionProperties(modelInspector, type).ToArray(); if (versionProperties.Length == 1) { classCustomizer.Version(versionProperties[0], m => m.Column(GetVersionColumnName(modelInspector, type))); } }