private bool IsUsiWithTransformedResourcePropertyName(EntityProperty property) { //Not: Use C# 7 '_' wildcard instead when available. string notUsed; //If the resource property name was flipped to a UniqueId for this USI property return(UniqueIdSpecification.IsUSI(property.PropertyName) && UniqueIdSpecification.TryGetUniqueIdPersonType(PropertyName, out notUsed)); }
public ResourceProperty(ResourceClassBase resourceClass, EntityProperty entityProperty) : base(resourceClass, GetResourcePropertyName(entityProperty)) { EntityProperty = entityProperty; string personType; // Assign property characteristics IsLookup = entityProperty.IsLookup; IsDirectLookup = entityProperty.IsDirectLookup; IsIdentifying = entityProperty.IsIdentifying || UniqueIdSpecification.TryGetUniqueIdPersonType(entityProperty.PropertyName, out personType) && personType == resourceClass.Name; IsLocallyDefined = entityProperty.IsLocallyDefined; IsServerAssigned = entityProperty.IsServerAssigned; LookupTypeName = entityProperty.LookupEntity == null ? null : entityProperty.LookupEntity.Name; DescriptorResource = entityProperty.LookupEntity == null ? null : resourceClass?.ResourceModel?.GetResourceByFullName(entityProperty.LookupEntity.FullName); PropertyType = GetResourcePropertyType(entityProperty); Description = entityProperty.Description; IsDeprecated = entityProperty.IsDeprecated; DeprecationReasons = entityProperty.DeprecationReasons; // Cannot just use resourceClass.Name here because properties may be from a base class which // produces a different result. Base class properties should retain their lineage // when "merged" into the resource model. ParentFullName = EntityProperty.Entity.FullName; }
private void ProcessQueryStringParameters(HqlBuilderContext builderContext, CompositeDefinitionProcessorContext processorContext) { // Get all non "special" query string parameter for property value equality processing var queryStringParameters = GetCriteriaQueryStringParameters(builderContext); foreach (var queryStringParameter in queryStringParameters) { ResourceProperty targetProperty; // TODO: Embedded convention. Types and descriptors at the top level if (processorContext.CurrentResourceClass.AllPropertyByName.TryGetValue(queryStringParameter.Key, out targetProperty)) { string criteriaPropertyName; object parameterValue; string personType; // Handle Lookup conversions if (targetProperty.IsLookup) { var id = _descriptorsCache.GetId( targetProperty.LookupTypeName, Convert.ToString(queryStringParameter.Value)); criteriaPropertyName = targetProperty.EntityProperty.PropertyName; parameterValue = id; } // Handle UniqueId conversions else if (UniqueIdSpecification.TryGetUniqueIdPersonType(targetProperty.PropertyName, out personType)) { int usi = _personUniqueIdToUsiCache.GetUsi(personType, Convert.ToString(queryStringParameter.Value)); // TODO: Embedded convention - Convert UniqueId to USI from Resource model to query Entity model on Person entities // The resource model maps uniqueIds to uniqueIds on the main entity(Student,Staff,Parent) if (PersonEntitySpecification.IsPersonEntity(targetProperty.ParentFullName.Name)) { criteriaPropertyName = targetProperty.EntityProperty.PropertyName.Replace("UniqueId", "USI"); } else { criteriaPropertyName = targetProperty.EntityProperty.PropertyName; } parameterValue = usi; } else { criteriaPropertyName = targetProperty.PropertyName; parameterValue = ConvertParameterValueForProperty(targetProperty, Convert.ToString(queryStringParameter.Value)); } // Add criteria to the query builderContext.SpecificationWhere.AppendFormat( "{0}{1}.{2} = :{2}", AndIfNeeded(builderContext.SpecificationWhere), builderContext.CurrentAlias, criteriaPropertyName); if (builderContext.CurrentQueryFilterParameterValueByName.ContainsKey(criteriaPropertyName)) { throw new ArgumentException( string.Format( "The value for parameter '{0}' was already assigned and cannot be reassigned using the query string.", criteriaPropertyName)); } builderContext.CurrentQueryFilterParameterValueByName[criteriaPropertyName] = parameterValue; } else { ThrowPropertyNotFoundException(queryStringParameter.Key); } } }