public static Expression GetOrderByExpression(Expression dto, PathToProperty sortPath) { var memberExpression = dto; sortPath.Traverse(x => memberExpression = Expression.PropertyOrField(memberExpression, x.Value.Name)); var property = memberExpression.Type.GetProperty(sortPath.Property.Name); var propertyAccess = Expression.MakeMemberAccess(memberExpression, property); return(propertyAccess); }
private void BuildStructuralTypes(QueryTypeLibrary library, EntityContainer container) { foreach (var entitySet in container.EntitySets) { var rootType = entitySet.EntityType; var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType)); foreach (var entityType in allDerivedTypes) { var queryEntityType = library.GetQueryEntityType(entitySet, entityType); var pathToProperty = new PathToProperty(container, entitySet, entityType); this.CreateMembers(library, queryEntityType, entityType.AllProperties, pathToProperty); ExceptionUtilities.Assert(pathToProperty.PathStackWithinEntityType.Count == 0, "Path to property stack is not empty."); this.CreateNavigationMembers(library, queryEntityType, entityType.AllNavigationProperties, container); } } }
/// <summary> /// Creates a QueryProperty for a property that is a non entity Collection /// </summary> /// <param name="library">Library Query Type</param> /// <param name="result">resulting Query Structural Type</param> /// <param name="collectionProperty">Member to calculate</param> /// <param name="pathToProperty">Path to the Property</param> /// <returns>A Query Property of the collectionType</returns> protected override QueryProperty CreateNonentityCollectionMember(QueryTypeLibrary library, QueryStructuralType result, MemberProperty collectionProperty, PathToProperty pathToProperty) { ExceptionUtilities.CheckArgumentNotNull(collectionProperty, "collectionProperty"); var collectionType = collectionProperty.PropertyType as CollectionDataType; ExceptionUtilities.Assert(collectionType != null, "This type of property is not supported."); var collectionPrimitiveElementType = collectionType.ElementDataType as PrimitiveDataType; var collectionComplexElementType = collectionType.ElementDataType as ComplexDataType; QueryCollectionType queryCollectionType = null; if (collectionPrimitiveElementType != null) { QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, collectionPrimitiveElementType); queryCollectionType = queryPropertyType.CreateCollectionType(); } else { ExceptionUtilities.Assert(collectionComplexElementType != null, "This type of property is not supported."); QueryComplexType queryComplexType = this.CreateStubComplexType(collectionComplexElementType.Definition); CreateMembers(library, queryComplexType, collectionComplexElementType.Definition.Properties, pathToProperty); queryCollectionType = queryComplexType.CreateCollectionType(); } return QueryProperty.Create(collectionProperty.Name, queryCollectionType); }
/// <summary> /// Creates a QueryProperty for a property that is a non entity Collection /// </summary> /// <param name="library">Library Query Type</param> /// <param name="result">resulting Query Structural Type</param> /// <param name="collectionProperty">Member to calculate</param> /// <param name="pathToProperty">Path to the Property</param> /// <returns>A Query Property of the collectionType</returns> protected override QueryProperty CreateNonentityCollectionMember(QueryTypeLibrary library, QueryStructuralType result, MemberProperty collectionProperty, PathToProperty pathToProperty) { ExceptionUtilities.CheckArgumentNotNull(collectionProperty, "collectionProperty"); var collectionType = collectionProperty.PropertyType as CollectionDataType; ExceptionUtilities.Assert(collectionType != null, "This type of property is not supported."); var collectionPrimitiveElementType = collectionType.ElementDataType as PrimitiveDataType; var collectionComplexElementType = collectionType.ElementDataType as ComplexDataType; QueryCollectionType queryCollectionType = null; if (collectionPrimitiveElementType != null) { QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, collectionPrimitiveElementType); queryCollectionType = queryPropertyType.CreateCollectionType(); } else { ExceptionUtilities.Assert(collectionComplexElementType != null, "This type of property is not supported."); QueryComplexType queryComplexType = this.CreateStubComplexType(collectionComplexElementType.Definition); CreateMembers(library, queryComplexType, collectionComplexElementType.Definition.Properties, pathToProperty); queryCollectionType = queryComplexType.CreateCollectionType(); } return(QueryProperty.Create(collectionProperty.Name, queryCollectionType)); }
/// <summary> /// Get the query type for a scalar property (with mapped store semantics, if applicable) /// </summary> /// <param name="pathToProperty">The path to find the property</param> /// <param name="library">The query type library</param> /// <param name="modelType">The model data type for the property</param> /// <returns>The query scalar type for the property</returns> /// <remarks>Default implementation just returns default type (meaning no special store semantics from mapping). Derived class should override as appropriate.</remarks> protected virtual QueryScalarType GetQueryTypeForMappedProperty(PathToProperty pathToProperty, QueryTypeLibrary library, PrimitiveDataType modelType) { return (QueryScalarType)library.GetDefaultQueryType(modelType); }
/// <summary> /// Creates new members on a structural type /// </summary> /// <param name="library">Type library</param> /// <param name="result">Structural Type to add members to</param> /// <param name="properties">Properties of the Structural Type member</param> /// <param name="pathToProperty">Path to the Property</param> protected void CreateMembers(QueryTypeLibrary library, QueryStructuralType result, IEnumerable<MemberProperty> properties, PathToProperty pathToProperty) { // TODO: Some Taupo framework pieces skip over StreamDataType properties foreach (var prop in properties.Where(p => !(p.PropertyType is StreamDataType))) { QueryProperty queryProperty = null; pathToProperty.PathStackWithinEntityType.Add(prop.Name); var pdt = prop.PropertyType as PrimitiveDataType; var cdt = prop.PropertyType as ComplexDataType; if (pdt != null) { QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, pdt); queryProperty = QueryProperty.Create(prop.Name, queryPropertyType); } else if (cdt != null) { ComplexType ct = cdt.Definition; QueryComplexType queryComplexType = this.CreateStubComplexType(ct); this.CreateMembers(library, queryComplexType, ct.Properties, pathToProperty); library.SetQueryComplexType(ct, queryComplexType); queryProperty = QueryProperty.Create(prop.Name, queryComplexType); } else { queryProperty = this.CreateNonentityCollectionMember(library, result, prop, pathToProperty); } pathToProperty.PathStackWithinEntityType.RemoveAt(pathToProperty.PathStackWithinEntityType.Count - 1); queryProperty.SetPrimaryKey(prop.IsPrimaryKey); result.Add(queryProperty); } }
/// <summary> /// Creates a QueryProperty for a property that is a non entity Collection /// </summary> /// <param name="library">Library Query Type</param> /// <param name="result">resulting Query Structural Type</param> /// <param name="collectionProperty">Member to calculate</param> /// <param name="pathToProperty">Path to the Property</param> /// <returns>A Query Property of the collectionType</returns> protected virtual QueryProperty CreateNonentityCollectionMember(QueryTypeLibrary library, QueryStructuralType result, MemberProperty collectionProperty, PathToProperty pathToProperty) { throw new TaupoNotSupportedException("This type of property is not supported."); }
/// <summary> /// Get the query type for a scalar property (with mapped store semantics, if applicable) /// </summary> /// <param name="pathToProperty">The path to find the property</param> /// <param name="library">The query type library</param> /// <param name="modelType">The model data type for the property</param> /// <returns>The query scalar type for the property</returns> /// <remarks>Default implementation just returns default type (meaning no special store semantics from mapping). Derived class should override as appropriate.</remarks> protected virtual QueryScalarType GetQueryTypeForMappedProperty(PathToProperty pathToProperty, QueryTypeLibrary library, PrimitiveDataType modelType) { return((QueryScalarType)library.GetDefaultQueryType(modelType)); }
/// <summary> /// Creates new members on a structural type /// </summary> /// <param name="library">Type library</param> /// <param name="result">Structural Type to add members to</param> /// <param name="properties">Properties of the Structural Type member</param> /// <param name="pathToProperty">Path to the Property</param> protected void CreateMembers(QueryTypeLibrary library, QueryStructuralType result, IEnumerable <MemberProperty> properties, PathToProperty pathToProperty) { // TODO: Some Taupo framework pieces skip over StreamDataType properties foreach (var prop in properties.Where(p => !(p.PropertyType is StreamDataType))) { QueryProperty queryProperty = null; pathToProperty.PathStackWithinEntityType.Add(prop.Name); var pdt = prop.PropertyType as PrimitiveDataType; var cdt = prop.PropertyType as ComplexDataType; if (pdt != null) { QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, pdt); queryProperty = QueryProperty.Create(prop.Name, queryPropertyType); } else if (cdt != null) { ComplexType ct = cdt.Definition; QueryComplexType queryComplexType = this.CreateStubComplexType(ct); this.CreateMembers(library, queryComplexType, ct.Properties, pathToProperty); library.SetQueryComplexType(ct, queryComplexType); queryProperty = QueryProperty.Create(prop.Name, queryComplexType); } else { queryProperty = this.CreateNonentityCollectionMember(library, result, prop, pathToProperty); } pathToProperty.PathStackWithinEntityType.RemoveAt(pathToProperty.PathStackWithinEntityType.Count - 1); queryProperty.SetPrimaryKey(prop.IsPrimaryKey); result.Add(queryProperty); } }