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 void EscapeAndMaybePluralizeEntityName(IModelInspector modelInspector, Type type, IClassAttributesMapper map) { if (Pluralize) { map.Table("`" + service.Pluralize(type.Name) + "`"); } else { map.Table("`" + type.Name + "`"); } }
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 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); } } }
protected void BeforeMapClass(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) { classCustomizer.Lazy(true); classCustomizer.Table(this.GetNormalizedDbName(type.Name)); classCustomizer.Id(type.GetProperty(String.Concat(type.Name, "Id")), map => { map.Column(this.GetNormalizedDbName(String.Concat(type.Name, "ID"))); map.Generator(new HighLowGeneratorDef()); }); }
//public static void PluralizeEntityName(Type type, IClassAttributesMapper map) //{ // map.Table(Service.Pluralize(type.Name)); //} public static void TableNameConvention(Type type, IClassAttributesMapper map) { var ns = type.Namespace; var prefix = NamespaceMapToTablePrefix[ns.Substring(ns.LastIndexOf(".") + 1)]; if (prefix == null) { throw new NetArchException("DomainObject's namespace has not been registered for table mapping:" + ns + "." + type.Name); } map.Table(prefix + type.Name); }
private void MapTable(Type type, IClassAttributesMapper map) { string table = type.Name; if (type.Name.EndsWith("y")) { table = type.Name.TrimEnd('y') + "ies"; } else if (!type.Name.EndsWith("s")) { table = type.Name + "s"; } map.Table(table); }
private static void ClassConvention(IModelInspector modelInspector, Type type, IClassAttributesMapper classAttributesMapper) { var schema = IdentityBuilder.BuildSchema(type.Namespace); classAttributesMapper.Schema(schema); var tableName = IdentityBuilder.BuildTableName(type.Name); classAttributesMapper.Table(tableName); classAttributesMapper.Id(im => { im.Generator(Generators.Assigned); im.Column(IdentityBuilder.BuildPrimaryKey(type.Name)); }); }
public static IClassAttributesMapper MapToTable <TOptions>(this IClassAttributesMapper classCustomizer, TableDefinition tableDefinition, TOptions options) where TOptions : StoreOptionsBase { classCustomizer.Table(tableDefinition.Name); if (string.IsNullOrEmpty(tableDefinition.Schema)) { classCustomizer.Schema(options.DefaultSchema); } else { classCustomizer.Schema(tableDefinition.Schema); } return(classCustomizer); }
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 ApplyClassConvention(IModelInspector mi, Type type, IClassAttributesMapper map) { if (!_sagaEntites.Contains(type)) { map.Id(idMapper => idMapper.Generator(Generators.GuidComb)); } else { map.Id(idMapper => idMapper.Generator(Generators.Assigned)); } var tableAttribute = GetAttribute <TableNameAttribute>(type); if (tableAttribute != null) { map.Table(tableAttribute.TableName); if (!String.IsNullOrEmpty(tableAttribute.Schema)) { map.Schema(tableAttribute.Schema); } } }
/// <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 MapTableName(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer) { classCustomizer.Table(Conventions.GetTableName(type)); }
private void PluralizeTableName(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer) { classCustomizer.Table(type.Pluralize()); }
public static void PluralizeEntityName(Type type, IClassAttributesMapper map) { map.Table(_service.Pluralize(type.Name)); }
public static void PluralizeEntityName(Type type, IClassAttributesMapper map) { map.Table(_service.Pluralize(type.Name)); }
public static void TableNameEnglishPluralizedConvention(IModelInspector modelInspector, Type type, IClassAttributesMapper map) { map.Table(EnglishPluralizationService.Pluralize(type.Name)); }
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))); } }