/// <summary>
 /// Sets the mapper to use:
 ///  1) a native generator for int primary keys
 ///  2) a Generators.GuidComb generator for Guid primary keys
 ///  3) a string length of 128 for string primary keys
 /// </summary>
 private void OnMapperOnBeforeMapClass(IModelInspector inspector, Type type, IClassAttributesMapper customizer)
 {
     foreach (var p in type.GetProperties())
     {
         if (inspector.IsPersistentId(p))
         {
             var idType = p.PropertyType;
             if (idType == typeof(int))
             {
                 customizer.Id(x => x.Generator(Generators.Native));
             }
             else if (idType == typeof(string))
             {
                 var customAttributes = p.GetCustomAttributes(false);
                 StringLengthAttribute stringlengthAttribute =
                     (StringLengthAttribute)
                     customAttributes.FirstOrDefault(x => x.GetType() == typeof(StringLengthAttribute));
                 int length = this.DefaltStringIdLength;
                 if (stringlengthAttribute != null && stringlengthAttribute.MaximumLength > 0)
                 {
                     length = stringlengthAttribute.MaximumLength;
                 }
                 customizer.Id(x => x.Length(length));
             }
             else if (idType == typeof(Guid))
             {
                 customizer.Id(x => { x.Generator(Generators.GuidComb); });
             }
         }
     }
 }
示例#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);
        }
        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)));
            }
        }
示例#4
0
 public static void PrimaryKeyConvention(Type type, IClassAttributesMapper map)
 {
     map.Id(k => {
         k.Generator(Generators.Native);
         k.Column(type.Name + "Id");
     });
 }
 private void ConfigurePoidGenerator(
     IModelInspector modelInspector, System.Type type,
     IClassAttributesMapper classCustomizer)
 {
     classCustomizer.Id(id =>
                        id.Generator(Generators.GuidComb));
 }
        /// <summary>
        /// Sets table name and table's schema following the rule that the table name is the same as the type name.
        /// </summary>
        /// <remarks>
        /// Exceptions to the rule:
        ///     - "ClientScope" class has to be mapped to the "ClientScopes" table.
        /// </remarks>
        private void BeforeMapConfigurationStoreClass(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
        {
            TableDefinition tableDef = null;

            if (type == typeof(ClientScope))
            {
                tableDef = GetTableDefinition(nameof(_options.ClientScopes), _options);
            }
            else
            {
                tableDef = GetTableDefinition(type.Name, _options);
            }

            if (tableDef != null)
            {
                classCustomizer.MapToTable(tableDef, _options);
            }

            // Common mapping rule for IDs
            classCustomizer.Id(map =>
            {
                map.Column("Id");
                map.Generator(Generators.Native);
            });
        }
示例#7
0
 public static void PrimaryKeyConvention(Type type, IClassAttributesMapper map)
 {
     map.Id(k =>
     {
         k.Generator(Generators.Identity);
         k.UnsavedValue(0);
     });
 }
示例#8
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);
                }
            }
        }
示例#9
0
 public static void PrimaryKeyConvention(Type type, IClassAttributesMapper map)
 {
     map.Id(k =>
     {
         k.Generator(Generators.Native);
         k.Column(type.Name + "Id");
     });
 }
示例#10
0
        protected virtual void NoSetterPoidToField(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer)
        {
            MemberInfo poidPropertyOrField = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(modelInspector.IsPersistentId);

            if (MatchNoSetterProperty(poidPropertyOrField))
            {
                classCustomizer.Id(idm => idm.Access(Accessor.NoSetter));
            }
        }
        protected virtual void NoPoidGuid(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
        {
            MemberInfo poidPropertyOrField = PoidPropertyOrField(modelInspector, type);

            if (ReferenceEquals(null, poidPropertyOrField))
            {
                classCustomizer.Id(null, idm => idm.Generator(Generators.Guid));
            }
        }
        protected virtual void NoSetterPoidToField(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
        {
            MemberInfo poidPropertyOrField = PoidPropertyOrField(modelInspector, type);

            if (poidPropertyOrField != null && MatchNoSetterProperty(poidPropertyOrField))
            {
                classCustomizer.Id(poidPropertyOrField, idm => idm.Access(Accessor.NoSetter));
            }
        }
示例#13
0
        protected virtual void NoPoidGuid(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer)
        {
            MemberInfo poidPropertyOrField = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(mi => modelInspector.IsPersistentId(mi));

            if (!ReferenceEquals(null, poidPropertyOrField))
            {
                return;
            }
            classCustomizer.Id(null, idm => idm.Generator(Generators.Guid));
        }
示例#14
0
        public static void DefaultClassMapper(IModelInspector modelInspector, Type type, IClassAttributesMapper mapper)
        {
            MapSchema(mapper.Schema, type);

            mapper.Id(id =>
            {
                id.Column(type.Name + _foreignKeyColumnPostfix);
                id.Generator(Generators.Identity);
            });
        }
 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 AutoMapper_BeforeMapClass(IModelInspector modelInspector, Type type,
                                              IClassAttributesMapper classCustomizer)
 {
     classCustomizer.Id(k =>
     {
         k.Generator(Generators.Identity);
         k.Column("Id");
         k.UnsavedValue("0");
     });
 }
示例#17
0
 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 => {});
     }
 }
示例#18
0
 private void PrimaryKeyConvention(IModelInspector modelInspector, Type type, IClassAttributesMapper map)
 {
     map.Id(k =>
     {
         foreach (var idProperty in type.GetProperties().Where(modelInspector.IsPersistentId))
         {
             if (IdColumnNaming != null)
             {
                 k.Column(IdColumnNaming(type, idProperty));
             }
         }
     });
 }
示例#19
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);
                }
            }
        }
示例#20
0
        private void MapIdentifier(Type type, IClassAttributesMapper map)
        {
            if (type.HasProperty("ID"))
            {
                string id = type.Name + "ID";
                var    p  = type.GetProperty("ID");

                if (p.PropertyType == typeof(Guid))
                {
                    map.Id(p, x => {
                        x.Column(id);
                        x.Generator(Generators.Guid);
                    });
                }
                else if (p.PropertyType == typeof(int) || p.PropertyType == typeof(long))
                {
                    map.Id(p, x => {
                        x.Column(id);
                        x.Generator(
                            Generators.HighLow,
                            y => y.Params(new {
                            table  = this.HiloTableName,
                            column = this.HiloColumnName,
                            max_lo = 100,
                            where  = String.Format("{0} = '{1}'", this.HiloEntityColumnName, type.Name.ToLowerInvariant())
                        })
                            );
                    });
                }
                else if (p.PropertyType == typeof(string))
                {
                    map.Id(p, x => {
                        x.Column(id);
                        x.Generator(Generators.Assigned);
                    });
                }
            }
        }
        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));
            });
        }
示例#22
0
        private void MapKey <T>(MemberInfoMetadata key, IClassAttributesMapper <T> classMapper)
            where T : class
        {
            object unsavedKeyValue = 0;

            if (key.Type == typeof(Guid))
            {
                unsavedKeyValue = Guid.Empty;
            }

            classMapper.Id(
                key.Name,
                m =>
            {
                AccessorHelper.SetAccessor(key, m);
                m.Generator(GetGenerator(key.Type));
                m.UnsavedValue(unsavedKeyValue);
            });
        }
示例#23
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));
            }
        }
		protected virtual void NoSetterPoidToField(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer)
		{
			MemberInfo poidPropertyOrField = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(modelInspector.IsPersistentId);
			if(MatchNoSetterProperty(poidPropertyOrField))
			{
				classCustomizer.Id(idm=> idm.Access(Accessor.NoSetter));
			}
		}
 public static void AllIdNamedPOIDAndHilo(IModelInspector modelInspector, Type type, IClassAttributesMapper map)
 {
     map.Id(x => x.Generator(Generators.HighLow));
     map.Id(x => x.Column("POID"));
     map.Id(x => x.Type(null));
 }
示例#26
0
 /// <summary>
 /// Sets the mapper to use:
 ///  1) a native generator for int primary keys
 ///  2) a Generators.GuidComb generator for Guid primary keys
 ///  3) a string length of 128 for string primary keys
 /// </summary>
 private void OnMapperOnBeforeMapClass(IModelInspector inspector, Type type, IClassAttributesMapper customizer)
 {
     foreach (var p in type.GetProperties())
     {
         if (inspector.IsPersistentId(p))
         {
             var idType = p.PropertyType;
             if (idType == typeof(int))
             {
                 customizer.Id(x => x.Generator(Generators.Native));
             }
             else if (idType == typeof(string))
             {
                 var customAttributes = p.GetCustomAttributes(false);
                 StringLengthAttribute stringlengthAttribute = (StringLengthAttribute)customAttributes.FirstOrDefault(x => x.GetType() == typeof(StringLengthAttribute));
                 int length = DefaltStringIdLength;
                 if (stringlengthAttribute != null && stringlengthAttribute.MaximumLength > 0)
                 {
                     length = stringlengthAttribute.MaximumLength;
                 }
                 customizer.Id(x => x.Length(length));
             }
             else if (idType == typeof(Guid))
             {
                 customizer.Id(x => { x.Generator(Generators.GuidComb); });
             }
         }
     }
 }
 protected virtual void NoSetterPoidToField(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
 {
     MemberInfo poidPropertyOrField = PoidPropertyOrField(modelInspector, type);
     if (poidPropertyOrField != null && MatchNoSetterProperty(poidPropertyOrField))
     {
         classCustomizer.Id(poidPropertyOrField, idm => idm.Access(Accessor.NoSetter));
     }
 }
 protected virtual void NoPoidGuid(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
 {
     MemberInfo poidPropertyOrField = PoidPropertyOrField(modelInspector, type);
     if (ReferenceEquals(null, poidPropertyOrField))
     {
         classCustomizer.Id(null, idm => idm.Generator(Generators.Guid));
     }
 }
        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)));
            }
        }
示例#30
0
 public void ApplyMapping(Attribute attribute, System.Reflection.MemberInfo idProperty, Type entityType, IClassAttributesMapper mapper, MappingContext context)
 {
     mapper.Id(idProperty, IdMappings.HighLowId(context.Conventions.GetTableName(entityType)));
 }
示例#31
0
文件: Class.cs 项目: solyutor/enhima
        private void MapHiloId(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
        {
            Mapper.AddHiLoScript(EntityHighLowGenerator.GetInsertFor(type));

            classCustomizer.Id(x => x.Generator(new EntityHighLowGeneratorDef(type)));
        }
		protected virtual void NoPoidGuid(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer)
		{
			MemberInfo poidPropertyOrField = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(mi => modelInspector.IsPersistentId(mi));
			if (!ReferenceEquals(null, poidPropertyOrField))
			{
				return;
			}
			classCustomizer.Id(null, idm=> idm.Generator(Generators.Guid));
		}
 public static void AllIdIdentity(IModelInspector modelinspector, Type type, IClassAttributesMapper classcustomizer)
 {
     classcustomizer.Id(x => x.Generator(Generators.Identity));
 }
示例#34
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));
            }
        }
 public static void AllIdHilo(IModelInspector modelinspector, Type type, IClassAttributesMapper classcustomizer)
 {
     classcustomizer.Id(x => x.Generator(Generators.HighLow));
 }