Beispiel #1
0
        internal override DbExpression AsCqt(bool isTopLevel)
        {
            // Get the FROM part.
            DbExpression cqt = m_extent.Scan();

            // Get the WHERE part only when the expression is not simply TRUE.
            if (!BoolExpression.EqualityComparer.Equals(WhereClause, BoolExpression.True))
            {
                cqt = cqt.Where(row => WhereClause.AsCqt(row));
            }

            // The SELECT/DISTINCT part.
            cqt = cqt.Select(row => GenerateProjectionCqt(row, isTopLevel));
            if (m_selectDistinct == CellQuery.SelectDistinct.Yes)
            {
                cqt = cqt.Distinct();
            }

            return(cqt);
        }
Beispiel #2
0
        // <summary>
        // This method creates a new ObjectQuery instance that represents a scan over
        // the specified <paramref name="entitySet" />. This ObjectQuery carries the scan as <see cref="DbExpression" />
        // and as Entity SQL. This is needed to allow case-sensitive metadata access (provided by the <see cref="DbExpression" /> by default).
        // The context specifies the connection on which to execute the query as well as the metadata and result cache.
        // The merge option specifies how the cache should be populated/updated.
        // </summary>
        // <param name="entitySet"> The entity set this query scans. </param>
        // <param name="context">
        // The ObjectContext containing the metadata workspace the query will be built against, the connection
        // on which to execute the query, and the cache to store the results in.
        // </param>
        // <param name="mergeOption"> The MergeOption to use when executing the query. </param>
        // <returns> A new ObjectQuery instance. </returns>
        internal ObjectQuery(EntitySetBase entitySet, ObjectContext context, MergeOption mergeOption)
            : this(new EntitySqlQueryState(typeof(T), BuildScanEntitySetEsql(entitySet), entitySet.Scan(), false, context, null, null))
        {
            EntityUtil.CheckArgumentMergeOption(mergeOption);
            QueryState.UserSpecifiedMergeOption = mergeOption;

            // SQLBUDT 447285: Ensure the assembly containing the entity's CLR type
            // is loaded into the workspace. If the schema types are not loaded
            // metadata, cache & query would be unable to reason about the type. We
            // either auto-load <T>'s assembly into the ObjectItemCollection or we
            // auto-load the user's calling assembly and its referenced assemblies.
            // If the entities in the user's result spans multiple assemblies, the
            // user must manually call LoadFromAssembly. *GetCallingAssembly returns
            // the assembly of the method that invoked the currently executing method.
            context.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(T), Assembly.GetCallingAssembly());
        }
 internal ObjectQuery(EntitySetBase entitySet, ObjectContext context, MergeOption mergeOption)
     : this((ObjectQueryState) new EntitySqlQueryState(typeof(T), ObjectQuery <T> .BuildScanEntitySetEsql(entitySet), (DbExpression)entitySet.Scan(), false, context, (ObjectParameterCollection)null, (Span)null, (ObjectQueryExecutionPlanFactory)null))
 {
     EntityUtil.CheckArgumentMergeOption(mergeOption);
     this.QueryState.UserSpecifiedMergeOption = new MergeOption?(mergeOption);
     context.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(T), Assembly.GetCallingAssembly());
 }