/// <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
        /// <summary>
        /// Returns the <see cref="PropertyPath"/> that is the entity's persistent ID.
        /// </summary>
        /// <param name="inspector">The model inspector.</param>
        /// <param name="type">The entity type.</param>
        /// <returns>The <see cref="PropertyPath"/> to the persistent ID, or null if one was not found.</returns>
        public static PropertyPath FindPersistentId(this IModelInspector inspector, Type type)
        {
            Requires.That(inspector, "inspector").IsNotNull();
            Requires.That(type, "type").IsNotNull();

            PropertyInfo property = (from prop in type.GetProperties()
                                     where inspector.IsPersistentId(prop)
                                     select prop).FirstOrDefault();

            return(property == null ? null : new PropertyPath(null, property));
        }
		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));
		}
Пример #4
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));
        }
Пример #5
0
 private void TryMapComponent(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
 {
     if (modelInspector.IsComponent(member.LocalMember.DeclaringType)
         && !modelInspector.IsPersistentId(member.PreviousPath.LocalMember))
     {
         propertyCustomizer.Column(member.PreviousPath.LocalMember.Name + "_" + member.LocalMember.Name);
     }
 }
Пример #6
0
        private void ApplyIdMappings(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer)
        {
            var member = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(m => modelInspector.IsPersistentId(m));

            if (member != null)
            {
                var idAttr = member.GetCustomAttributes(typeof(IdAttribute), false).OfType<IdAttribute>().FirstOrDefault();

                // If IdAttribute is not specified for persistent id property, then use the default id mapping strategy
                if (idAttr == null)
                {
                    idAttr = new IdAttribute();
                }

                var context = new MappingContext(modelInspector, Conventions);

                foreach (var mapper in _attributeMapperFactory.GetIdAttributeMappers(idAttr))
                {
                    mapper.ApplyMapping(idAttr, member, type, classCustomizer, context);
                }
            }
        }
Пример #7
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); });
             }
         }
     }
 }