Пример #1
0
        /// <summary>
        /// Initializes a new instance of the QueryKeyStructuralValue class.
        /// </summary>
        /// <param name="entityInstance">Entity Instance</param>
        internal QueryKeyStructuralValue(QueryEntityValue entityInstance)
            : base(entityInstance.Type, false, null, entityInstance.Type.EvaluationStrategy)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityInstance, "entityInstance");

            this.queryEntityType = entityInstance.Type as QueryEntityType;
            this.keyProperties   = this.queryEntityType.Properties.Where(p => p.IsPrimaryKey).ToList();

            ExceptionUtilities.CheckObjectNotNull(this.queryEntityType, "queryEntityType");
            ExceptionUtilities.Assert(this.keyProperties.Count > 0, "There are no key properties on QueryEntityType '{0}'", this.queryEntityType);

            foreach (QueryProperty keyProperty in this.keyProperties)
            {
                this.SetValue(keyProperty.Name, entityInstance.GetScalarValue(keyProperty.Name));
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a key structural value for a QueryEntityValue
        /// </summary>
        /// <param name="queryEntityType">Query Entity Type that has key metadata to extract key information</param>
        /// <param name="entityInstance">Entity Instance object value that contains the key</param>
        /// <returns>A Query Key Structural Value</returns>
        public static QueryKeyStructuralValue GetEntityInstanceKey(this QueryEntityType queryEntityType, object entityInstance)
        {
            ExceptionUtilities.CheckArgumentNotNull(queryEntityType, "queryEntityType");
            ExceptionUtilities.CheckArgumentNotNull(entityInstance, "entityInstance");
            ExceptionUtilities.Assert(queryEntityType.ClrType.IsAssignableFrom(entityInstance.GetType()), "entityInstance of type '{0}' is not assignable to queryEntityType '{1}'", entityInstance.GetType(), queryEntityType.EntityType.FullName);

            QueryEntityValue keyValueContainer = new QueryEntityValue(queryEntityType, false, null, queryEntityType.EvaluationStrategy);

            foreach (QueryProperty keyProperty in queryEntityType.Properties.Where(m => m.IsPrimaryKey))
            {
                PropertyInfo pi = entityInstance.GetType().GetProperty(keyProperty.Name);
                keyValueContainer.SetPrimitiveValue(keyProperty.Name, pi.GetValue(entityInstance, null));
            }

            return(new QueryKeyStructuralValue(keyValueContainer));
        }
Пример #3
0
        /// <summary>
        /// Gets the related entity type for the given navigation property on the entity type
        /// </summary>
        /// <param name="entityType">The entity type</param>
        /// <param name="navigationPropertyName">The name of the navigation property</param>
        /// <returns>The entity type related to the current one via the navigation property</returns>
        public static QueryEntityType GetRelatedEntityType(this QueryEntityType entityType, string navigationPropertyName)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");
            ExceptionUtilities.CheckArgumentNotNull(navigationPropertyName, "navigationPropertyName");

            var propertyType = entityType.Properties.Where(p => p.Name == navigationPropertyName).Select(p => p.PropertyType).SingleOrDefault();

            ExceptionUtilities.CheckObjectNotNull(propertyType, "Could not find type of property '{0}' on type '{1}'", navigationPropertyName, entityType.StringRepresentation);

            QueryEntityType propertyEntityType = propertyType as QueryEntityType;

            if (propertyEntityType == null)
            {
                var collectionType = propertyType as QueryCollectionType;
                ExceptionUtilities.CheckObjectNotNull(collectionType, "Property '{0}' on type '{1}' was neither an entity nor collection type. Type was '{2}'", navigationPropertyName, entityType.StringRepresentation, propertyType.StringRepresentation);
                propertyEntityType = collectionType.ElementType as QueryEntityType;
            }

            ExceptionUtilities.CheckObjectNotNull(propertyEntityType, "Property '{0}' on type '{1}' was neither an entity nor collection type. Type was '{2}'", navigationPropertyName, entityType.StringRepresentation, propertyType.StringRepresentation);
            return(propertyEntityType);
        }
Пример #4
0
        internal void SetReferenceValue(QueryStructuralValue entityValue)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityValue, "entityValue");
            this.EntityValue = entityValue;

            // compute key value
            QueryEntityType entityType = this.Type.QueryEntityType;
            var             keyType    = new QueryRecordType(this.EvaluationStrategy);

            keyType.AddProperties(entityType.Properties.Where(m => m.IsPrimaryKey));

            this.KeyValue = keyType.CreateNewInstance();

            for (int i = 0; i < keyType.Properties.Count; i++)
            {
                this.KeyValue.SetMemberValue(i, entityValue.GetValue(keyType.Properties[i].Name));
            }

            var set = entityType.EntitySet;

            this.EntitySetFullName = set.Container.Name + "." + set.Name;
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the QueryEntityValue class.
 /// </summary>
 /// <param name="type">The type of the value.</param>
 /// <param name="isNull">If set to <c>true</c> the structural value is null.</param>
 /// <param name="evaluationError">The evaluation error.</param>
 /// <param name="evaluationStrategy">The evaluation strategy.</param>
 internal QueryEntityValue(QueryEntityType type, bool isNull, QueryError evaluationError, IQueryEvaluationStrategy evaluationStrategy)
     : base(type, isNull, evaluationError, evaluationStrategy)
 {
     this.navigateResultLookup = new Dictionary <AssociationType, Dictionary <AssociationEnd, QueryValue> >();
 }
Пример #6
0
 /// <summary>
 /// Sets query type for a given entity type
 /// </summary>
 /// <param name="entitySet">The entity set</param>
 /// <param name="entityType">The entity type</param>
 /// <param name="queryType">The corresponding query type to be set</param>
 internal void SetQueryEntityType(EntitySet entitySet, EntityType entityType, QueryEntityType queryType)
 {
     this.queryEntityTypeCache[GetCacheKey(entitySet.Container, entitySet, entityType)] = queryType;
     this.defaultQueryEntityTypes[entityType] = queryType;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the QueryReferenceType class.
 /// </summary>
 /// <param name="evaluationStrategy">The evaluation strategy</param>
 /// <param name="queryEntityType">The referenced query entity type</param>
 internal QueryReferenceType(IQueryEvaluationStrategy evaluationStrategy, QueryEntityType queryEntityType)
     : base(evaluationStrategy)
 {
     ExceptionUtilities.CheckArgumentNotNull(queryEntityType, "queryEntityType");
     this.QueryEntityType = queryEntityType;
 }