Exemplo n.º 1
0
 private void Name(IPropertyMapper propertyMapper)
 {
     propertyMapper.Column("Name");
     propertyMapper.Type(NHibernateUtil.String);
     propertyMapper.Length(100);
     propertyMapper.NotNullable(false);
 }
        private static void PropertyConvension(IModelInspector modelInspector,
                                               PropertyPath propertyPath,
                                               IPropertyMapper propertyMapper)
        {
            if (modelInspector.IsSet(propertyPath.LocalMember))
            {
                propertyMapper.Access(Accessor.Field);
            }

            var type = propertyPath.LocalMember.GetPropertyOrFieldType();

            if (!type.IsNullable())
            {
                propertyMapper.NotNullable(true);
            }

            var propertyName = propertyPath.LocalMember.Name;

            if (modelInspector.IsComponent(propertyPath.LocalMember.ReflectedType))
            {
                var entityName = propertyPath.LocalMember.ReflectedType.Name;

                propertyMapper.Column(IdentityBuilder.BuildColumnName(entityName,
                                                                      propertyName));
            }
            else
            {
                propertyMapper.Column(IdentityBuilder.BuildColumnName(propertyName));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Applies any conventions required for persistable properties.
        /// </summary>
        /// <param name="attributes"> Attributes present on the property. </param>
        /// <param name="mapper"> The property mapper. </param>
        /// <param name="property"> The property. </param>
        /// <param name="propertyType"> The property type. </param>
        protected virtual void ApplyPropertyConventions(IPropertyMapper mapper, PropertyPath property, Type propertyType,
                                                        IEnumerable <Attribute> attributes)
        {
            mapper.NotNullable(!IsNullable(propertyType, attributes));

            if (propertyType.IsEnum)
            {
                mapper.Type <Int32Type>();
            }
        }
        /// <summary>
        /// Sets the mapper to use:
        ///  1) a properties StringLength attribute if it has one for the databases field size.
        ///  2) non-nullable types to be not nullable in the database.
        ///  3) creates indexes based on the index attributes of properties.
        /// </summary>
        private void OnMapperOnBeforeMapProperty(
            IModelInspector inspector,
            PropertyPath member,
            IPropertyMapper customizer)
        {
            // Get all the custom attributes.
            var customAttributes = member.LocalMember.GetCustomAttributes(false);

            // For all types check for index attributes and add indexes if required.
            var indexAttributes = customAttributes.OfType <IndexAttribute>();

            foreach (var indexAttribute in indexAttributes)
            {
                string indexPrefix = member.GetContainerEntity(inspector).Name;
                if (indexAttribute.Unique)
                {
                    string indexName = $"UI_{indexPrefix}_{indexAttribute.Name}";
                    customizer.UniqueKey(indexName);
                }
                else
                {
                    string indexName = $"IX_{indexPrefix}_{indexAttribute.Name}";
                    customizer.Index(indexName);
                }
            }

            // For string types check for string length attribute and set field length if required
            Type memberType = member.LocalMember.GetPropertyOrFieldType();

            if (memberType == typeof(string))
            {
                StringLengthAttribute stringlengthAttribute =
                    (StringLengthAttribute)
                    customAttributes.FirstOrDefault(x => x.GetType() == typeof(StringLengthAttribute));
                int length = this.DefaltStringLength;
                if (stringlengthAttribute != null && stringlengthAttribute.MaximumLength > 0)
                {
                    length = stringlengthAttribute.MaximumLength;
                }
                customizer.Length(length);
            }

            // For all types if the type is not nullable then set not nullable to true.
            if (!IsNullable(memberType))
            {
                customizer.NotNullable(true);
            }
        }
        protected override void OnBeforeMapProperty(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
        {
            Type reflectedType = member.LocalMember.ReflectedType;

            if (reflectedType == null)
            {
                return;
            }

            propertyCustomizer.Column(GetColumnName(modelInspector, member));

            bool required =
                member.LocalMember
                .GetCustomAttributes()
                .OfType <RequiredAttribute>()
                .Any();

            // Getting tableType of reflected object
            Type memberType = member.MemberType();

            bool notNullable = required || (memberType != null && memberType.IsPrimitive) || memberType == typeof(DateTime);

            propertyCustomizer.NotNullable(notNullable);

            StringLengthAttribute stringLengthAttribute =
                member.LocalMember
                .GetCustomAttributes()
                .OfType <StringLengthAttribute>()
                .FirstOrDefault();

            if (stringLengthAttribute != null)
            {
                if (stringLengthAttribute.MaximumLength > 0)
                {
                    propertyCustomizer.Length(stringLengthAttribute.MaximumLength);
                }
                else
                {
                    propertyCustomizer.Type(NHibernateUtil.StringClob);
                }
            }
        }
Exemplo n.º 6
0
 private static void SetNotNullable(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
 {
     propertyCustomizer.NotNullable(member.IsNotNullable());
 }
Exemplo n.º 7
0
 private void TeamId(IPropertyMapper propertyMapper)
 {
     propertyMapper.Column("Team_Id");
     propertyMapper.Type(NHibernateUtil.Int32);
     propertyMapper.NotNullable(false);
 }
Exemplo n.º 8
0
 private static void MapProperty(IModelInspector modelinspector, PropertyPath member, IPropertyMapper prop)
 {
     prop.NotNullable(true);
 }
        protected override void OnBeforeMapProperty(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
        {
            Type reflectedType = member.LocalMember.ReflectedType;
            if (reflectedType == null)
            {
                return;
            }

            propertyCustomizer.Column(GetColumnName(modelInspector, member));

            bool required =
                member.LocalMember
                      .GetCustomAttributes()
                      .OfType<RequiredAttribute>()
                      .Any();

            // Getting tableType of reflected object
            Type memberType = member.MemberType();

            bool notNullable = required || (memberType != null && memberType.IsPrimitive) || memberType == typeof(DateTime);
            propertyCustomizer.NotNullable(notNullable);

            StringLengthAttribute stringLengthAttribute =
                member.LocalMember
                      .GetCustomAttributes()
                      .OfType<StringLengthAttribute>()
                      .FirstOrDefault();
            if (stringLengthAttribute != null)
            {
                if (stringLengthAttribute.MaximumLength > 0)
                {
                    propertyCustomizer.Length(stringLengthAttribute.MaximumLength);
                }
                else
                {
                    propertyCustomizer.Type(NHibernateUtil.StringClob);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the mapper to use:
        ///  1) a properties StringLength attribute if it has one for the databases field size.
        ///  2) non-nullable types to be not nullable in the database.
        ///  3) creates indexes based on the index attributes of properties.
        /// </summary>
        private void OnMapperOnBeforeMapProperty(IModelInspector inspector, PropertyPath member, IPropertyMapper customizer)
        {
            // Get all the custom attributes.
            var customAttributes = member.LocalMember.GetCustomAttributes(false);

            // For all types check for index attributes and add indexes if required.
            var indexAttributes = customAttributes.OfType<IndexAttribute>();
            foreach (var indexAttribute in indexAttributes)
            {
                string indexPrefix = member.GetContainerEntity(inspector).Name;
                if (indexAttribute.Unique)
                {
                    string indexName = string.Format("UI_{0}_{1}", indexPrefix, indexAttribute.Name);
                    customizer.UniqueKey(indexName);
                }
                else
                {
                    string indexName = string.Format("IX_{0}_{1}", indexPrefix, indexAttribute.Name);
                    customizer.Index(indexName);
                }
            }

            // For string types check for string length attribute and set field length if required
            Type memberType = member.LocalMember.GetPropertyOrFieldType();
            if (memberType == typeof(string))
            {
                StringLengthAttribute stringlengthAttribute = (StringLengthAttribute)customAttributes.FirstOrDefault(x => x.GetType() == typeof(StringLengthAttribute));
                int length = DefaltStringLength;
                if (stringlengthAttribute != null && stringlengthAttribute.MaximumLength > 0)
                {
                    length = stringlengthAttribute.MaximumLength;
                }
                customizer.Length(length);
            }

            // For all types if the type is not nullable then set not nullable to true.
            if (!IsNullable(memberType))
            {
                customizer.NotNullable(true);
            }
        }