/// <summary> /// Возвращает таблицу с дополнительными данными для ассоциации many-to-many /// </summary> /// <param name="property">Свойство, устанавливающее ассоциацию</param> /// <param name="tableName">Название таблицы</param> /// <returns>Таблица для ассоциации many-to-many</returns> public DBTableEx GetIntermediateTableEx(ReflectionPropertyInfo property, string tableName) { DBTableEx table = new DBTableEx(tableName, property.IntermediateClass.Table); if (IsCustomPersistent) { string associationName = ((AssociationAttribute)property.Attributes.First(a => a is AssociationAttribute)).Name; table.CustomPersistent = GetCustomPersistent(associationName); } return table; }
private FieldValidationResult ValidateProperty( ReflectionPropertyInfo reflectionPropertyInfo, object mainObject, int?index) { var propertyInfo = reflectionPropertyInfo.Property; var propertyType = reflectionPropertyInfo.Property.PropertyType; var propertyValue = propertyInfo.GetValue(mainObject); var validationAttributes = reflectionPropertyInfo.CustomAttributes .Where(attribute => attribute is IValidationAttribute) .Select(attribute => (IValidationAttribute)attribute) .ToList(); var validationContext = new ValidationContext(mainObject); var errorCodes = validationAttributes .Where(validationAttrbute => validationAttrbute.IsValid(propertyValue, validationContext) != null) .Select(validationAttribute => validationAttribute.GetErrorCode()) .ToList(); //In case of notrequiredattribute this will override any required codes if (reflectionPropertyInfo.CustomAttributes.Any(x => x is FsNotRequiredAttribute)) { errorCodes = errorCodes .Where(x => x != FieldValidationErrorCode.Required) .ToList(); } var subFieldValidationResults = new List <FieldValidationResult>(); if (propertyValue != null) { var metadataType = _reflectionService.GetMetadataType(propertyType); if (metadataType != null) { var propertyValidationResults = ValidateSingularObject(propertyValue); subFieldValidationResults.AddRange(subFieldValidationResults); } else if (_reflectionService.IsCollection(propertyType)) { var elementList = (IEnumerable)propertyValue; var subIndex = 0; foreach (var element in elementList) { var elementValidationResults = ValidateSingularObject(element, subIndex); subFieldValidationResults.AddRange(elementValidationResults); subIndex++; } } } if (subFieldValidationResults.Any()) { return(new FieldValidationResult(propertyInfo.Name, errorCodes, subFieldValidationResults, index)); } else { return(new FieldValidationResult(propertyInfo.Name, errorCodes, index)); } }