コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
            });
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        /// <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));
            }
        }