public override string GetSqlName(PropertyDescriptor propertyDescriptor) { var sizeConstraintAttribute = propertyDescriptor == null ? null : propertyDescriptor.PropertyInfo.GetFirstCustomAttribute<SizeConstraintAttribute>(true); if (sizeConstraintAttribute != null) { switch (sizeConstraintAttribute.SizeFlexibility) { case SizeFlexibility.Fixed: return String.Concat("CHAR(", sizeConstraintAttribute.MaximumLength, ")"); case SizeFlexibility.Variable: return String.Concat("VARCHAR(", sizeConstraintAttribute.MaximumLength, ")"); case SizeFlexibility.LargeVariable: return "TEXT"; default: throw new NotSupportedException("SizeFlexibility: " + sizeConstraintAttribute.SizeFlexibility); } } else { if (propertyDescriptor.IsPrimaryKey || propertyDescriptor.HasUniqueAttribute || propertyDescriptor.IndexAttributes.Count > 0) { return "VARCHAR(" + constraintDefaults.IndexedStringMaximumLength + ")"; } else { return "VARCHAR(" + constraintDefaults.StringMaximumLength + ")"; } } }
public override string GetSqlName(PropertyDescriptor propertyDescriptor) { var typeDescriptorProvider = propertyDescriptor.DeclaringTypeDescriptor.TypeDescriptorProvider; var enumTypeDescriptor = typeDescriptorProvider.GetEnumTypeDescriptor(underlyingType ?? this.SupportedType); return enumTypeDescriptor.Name; }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { var sizeConstraintAttribute = propertyDescriptor?.PropertyInfo.GetFirstCustomAttribute<SizeConstraintAttribute>(true); if (sizeConstraintAttribute != null || constraintDefaults?.StringSizeFlexibility != null) { switch ((constraintDefaults?.StringSizeFlexibility ?? sizeConstraintAttribute.SizeFlexibility)) { case SizeFlexibility.Fixed: return CreateFixedTypeName(sizeConstraintAttribute.MaximumLength); case SizeFlexibility.Variable: return CreateVariableName(sizeConstraintAttribute.MaximumLength); case SizeFlexibility.LargeVariable: return CreateTextName(); default: throw new NotSupportedException("SizeFlexibility: " + sizeConstraintAttribute.SizeFlexibility); } } else { if (propertyDescriptor != null && (propertyDescriptor.IsPrimaryKey || propertyDescriptor.HasUniqueAttribute || propertyDescriptor.IndexAttributes.Count > 0)) { return this.CreateVariableName(this.constraintDefaultsConfiguration.IndexedStringMaximumLength); } else { return this.CreateVariableName((constraintDefaults ?? this.constraintDefaultsConfiguration).StringMaximumLength); } } }
internal string GetSuffixName(PropertyDescriptor property, string transformString = "") { return VariableSubstituter.SedTransform(VariableSubstituter.Substitute(this.SuffixName, property), transformString); }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { return "INTERVAL"; }
public override string GetSqlName(PropertyDescriptor propertyDescriptor) { return "INTERVAL"; }
internal static ObjectPropertyValue Create(PropertyDescriptor property, object target) { var value = property.PropertyInfo.GetValue(target); return new ObjectPropertyValue(property.PropertyType, property.PropertyName, property.PersistedName, property.PropertyName.GetHashCode(), value); }
public override string GetSqlName(PropertyDescriptor propertyDescriptor) { return this.sqlDataTypeProvider.GetSqlDataType(typeof(long)).GetSqlName(propertyDescriptor); }
public TypeDescriptor(TypeDescriptorProvider typeDescriptorProvider, Type type) { var propertyDescriptorsInOrder = new List<PropertyDescriptor>(); this.Type = type; this.TypeDescriptorProvider = typeDescriptorProvider; this.DataAccessObjectAttribute = type.GetFirstCustomAttribute<DataAccessObjectAttribute>(true); this.relationshipInfos = new Dictionary<TypeDescriptor, TypeRelationshipInfo>(); this.propertyDescriptorByColumnName = new Dictionary<string, PropertyDescriptor>(); this.propertyDescriptorByPropertyName = new Dictionary<string, PropertyDescriptor>(); var alreadyEnteredProperties = new HashSet<string>(); foreach (var propertyInfo in this.GetPropertiesInOrder()) { if (alreadyEnteredProperties.Contains(propertyInfo.Name)) { continue; } alreadyEnteredProperties.Add(propertyInfo.Name); var attribute = propertyInfo.GetFirstCustomAttribute<PersistedMemberAttribute>(true); if (attribute != null) { var propertyDescriptor = new PropertyDescriptor(this, type, propertyInfo); if (propertyInfo.GetGetMethod() == null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is missing a required getter method", propertyInfo.Name); } if (propertyInfo.GetSetMethod() == null && !propertyDescriptor.IsComputedTextMember && !propertyDescriptor.IsComputedMember) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is missing a required setter method", propertyInfo.Name); } if (!IsValidDataType(propertyInfo.PropertyType)) { throw new InvalidDataAccessObjectModelDefinition("The property {0} cannot have a return type of {1}", propertyInfo.Name, propertyInfo.PropertyType.Name); } if (!(propertyInfo.GetGetMethod().IsAbstract || propertyInfo.GetGetMethod().IsVirtual)) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is not virtual or abstract", propertyInfo.Name, type.Name); } propertyDescriptorsInOrder.Add(propertyDescriptor); this.propertyDescriptorByPropertyName[propertyInfo.Name] = propertyDescriptor; this.propertyDescriptorByColumnName[attribute.GetName(propertyInfo, this)] = propertyDescriptor; } } var relatedProperties = new List<PropertyDescriptor>(); foreach (var propertyInfo in this.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (propertyInfo.GetFirstCustomAttribute<DataAccessObjectsAttribute>(true) != null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is decorated with a DataAccessObjects attribute. Did you mean to you use RelatedDataAccessObjects attribute?", propertyInfo.Name, this.Type.Name); } if (propertyInfo.GetFirstCustomAttribute<RelatedDataAccessObjectsAttribute>(true) != null) { if (!typeof(RelatedDataAccessObjects<>).IsAssignableFromIgnoreGenericParameters(propertyInfo.PropertyType.GetGenericTypeDefinition())) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is decorated with a RelatedDataAccessObjectsAttribute but the property type does not extend RelatedDataAccessObjects<OBJECT_TYPE>", this.Type.Name, propertyInfo.Name); } if (propertyInfo.GetSetMethod() != null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is a related objects property and should not define a setter method", propertyInfo.Name); } if (propertyInfo.GetGetMethod() == null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is missing a required getter method", propertyInfo.Name); } if (!(propertyInfo.GetGetMethod().IsAbstract || propertyInfo.GetGetMethod().IsVirtual)) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is not virtual or abstract", propertyInfo.Name, type.Name); } var propertyDescriptor = new PropertyDescriptor(this, this.Type, propertyInfo); relatedProperties.Add(propertyDescriptor); this.propertyDescriptorByPropertyName[propertyInfo.Name] = propertyDescriptor; } else if (propertyInfo.GetFirstCustomAttribute<BackReferenceAttribute>(true) != null) { if (!propertyInfo.PropertyType.IsDataAccessObjectType()) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is decorated with a BackReference attribute but does not return a type that extends DataAccessObject<OBJECT_TYPE>", propertyInfo.Name, this.Type.Name); } if (propertyInfo.GetGetMethod() == null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is missing a required getter method", propertyInfo.Name); } if (propertyInfo.GetSetMethod() == null) { throw new InvalidDataAccessObjectModelDefinition("The property {0} is missing a required setter method", propertyInfo.Name); } if (!(propertyInfo.GetGetMethod().IsAbstract || propertyInfo.GetGetMethod().IsVirtual)) { throw new InvalidDataAccessObjectModelDefinition("The property {0} on {1} is not virtual or abstract", propertyInfo.Name, type.Name); } var propertyDescriptor = new PropertyDescriptor(this, this.Type, propertyInfo); relatedProperties.Add(propertyDescriptor); this.propertyDescriptorByPropertyName[propertyInfo.Name] = propertyDescriptor; } } this.RelatedProperties = new ReadOnlyList<PropertyDescriptor>(relatedProperties); this.PersistedProperties = new ReadOnlyList<PropertyDescriptor>(propertyDescriptorsInOrder); this.PrimaryKeyProperties = new ReadOnlyList<PropertyDescriptor>(this.PersistedProperties.Where(propertyDescriptor => propertyDescriptor.IsPrimaryKey).ToList()); this.ComputedTextProperties = new ReadOnlyList<PropertyDescriptor>(this.PersistedProperties.Where(c => c.IsComputedTextMember && !String.IsNullOrEmpty(c.ComputedTextMemberAttribute.Format)).ToList()); this.ComputedProperties = new ReadOnlyList<PropertyDescriptor>(this.PersistedProperties.Where(c => c.IsComputedMember && !String.IsNullOrEmpty(c.ComputedMemberAttribute.Expression)).ToList()); this.PersistedAndRelatedObjectProperties = new ReadOnlyList<PropertyDescriptor>(this.PersistedProperties.Concat(this.RelatedProperties.Where(c => c.IsBackReferenceProperty)).ToList()); if (this.PrimaryKeyProperties.Count(c => c.IsPropertyThatIsCreatedOnTheServerSide) > 1) { throw new InvalidDataAccessObjectModelDefinition("An object can only define one integer auto increment property"); } }
internal void AddRelationshipInfo(RelationshipType relationshipType, PropertyDescriptor relatingProperty, PropertyDescriptor targetProperty) { this.relationshipInfos.Add(new TypeRelationshipInfo(relationshipType, relatingProperty, targetProperty)); }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { return this.sqlName; }
public override string GetSqlName(PropertyDescriptor propertyDescriptor) { return "CHAR(32)"; }
public static string Substitute(string input, PropertyDescriptor property) { return(Substitute(input, new[] { property })); }
public static string SedTransform(string value, string transformString, PropertyDescriptor property) { return(SedTransform(value, transformString, new[] { property })); }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { var enumTypeDescriptor = this.typeDescriptorProvider.GetEnumTypeDescriptor(this.underlyingType ?? this.SupportedType); return enumTypeDescriptor.Name; }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { return this.sqlDataTypeProvider.GetSqlDataType(typeof(long)).GetSqlName(propertyDescriptor); }
public TypeRelationshipInfo SetOrCreateRelationshipInfo(TypeDescriptor relatedTypeDescriptor, EntityRelationshipType entityRelationshipType, PropertyDescriptor relatedProperty) { TypeRelationshipInfo retval; if (this.relationshipInfos.TryGetValue(relatedTypeDescriptor, out retval)) { retval.EntityRelationshipType = entityRelationshipType; retval.ReferencingProperty = relatedProperty; retval.RelatedTypeTypeDescriptor = relatedTypeDescriptor; return retval; } retval = new TypeRelationshipInfo(relatedTypeDescriptor, entityRelationshipType, relatedProperty); this.relationshipInfos[relatedTypeDescriptor] = retval; return retval; }
/// <summary> /// Gets the SQL type name for the given property. /// </summary> /// <param name="propertyDescriptor">The property whose return type is to be serialized</param> /// <returns>The SQL type name</returns> public string GetSqlName(PropertyDescriptor propertyDescriptor) { return GetSqlName(propertyDescriptor, null); }
public override string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults) { return(this.dateTimeDataType.GetSqlName(propertyDescriptor, constraintDefaults)); }
/// <summary> /// Gets the SQL type name for the given property. /// </summary> /// <returns>The SQL type name</returns> public abstract string GetSqlName(PropertyDescriptor propertyDescriptor, ConstraintDefaultsConfiguration constraintDefaults);
/// <summary> /// Gets the SQL type name for the given property. /// </summary> /// <param name="propertyDescriptor">The proeprty whose return type is to be serialized</param> /// <returns>The SQL type name</returns> public abstract string GetSqlName(PropertyDescriptor propertyDescriptor);
public TypeRelationshipInfo(RelationshipType relationshipType, PropertyDescriptor referencingProperty, PropertyDescriptor targetProperty) { this.RelationshipType = relationshipType; this.ReferencingProperty = referencingProperty; this.TargetProperty = targetProperty; }
public override string GetSqlName(PropertyDescriptor propertyDescriptor) { return sqlName; }
public static string Substitute(string pattern, PropertyDescriptor propertyDescriptor) { var root = false; if (pattern == null) { return propertyDescriptor.PropertyName; } if (visitedProperties == null) { root = true; visitedProperties = new HashSet<PropertyDescriptor>(); } try { visitedProperties.Add(propertyDescriptor); return Substitute(pattern, value => { switch (value.ToUpper()) { case "TYPENAME": return propertyDescriptor.DeclaringTypeDescriptor.TypeName; case "PROPERTYNAME": return propertyDescriptor.PropertyName; case "PROPERTYTYPENAME": return propertyDescriptor.PropertyType.Name; case "TABLENAME": case "PERSISTED_TYPENAME": return propertyDescriptor.DeclaringTypeDescriptor.PersistedName; case "COLUMNNAME": case "PERSISTED_PROPERTYNAME": return propertyDescriptor.PersistedName; case "COLUMNTYPENAME": case "PERSISTED_PROPERTYTYPENAME": return propertyDescriptor.PropertyTypeTypeDescriptor.PersistedName; default: throw new NotSupportedException(value); } }); } finally { visitedProperties.Remove(propertyDescriptor); Debug.Assert(!root || (root && visitedProperties.Count == 0)); } }