src/Shared/EntityFramework/Core/Objects/ObjectQuery`.cs
/// <summary>Limits the query to only results of a specific type.</summary>
/// <returns>
/// A new <see cref="T:System.Data.Entity.Core.Objects.ObjectQuery`1" /> instance that is equivalent to the original instance with OFTYPE applied.
/// </returns>
/// <typeparam name="TResultType">
/// The type of the <see cref="T:System.Data.Entity.Core.Objects.ObjectResult`1" /> returned when the query is executed with the applied filter.
/// </typeparam>
/// <exception cref="T:System.Data.Entity.Core.EntitySqlException">The type specified is not valid.</exception>
Limits the query to only results of a specific type.
Limits the query to only results of a specific type .
public ObjectQuery<TResultType> OfType<TResultType>()
        {
            if (IsLinqQuery(this))
            {
                return (ObjectQuery<TResultType>)Queryable.OfType<TResultType>(this);
            }
            QueryState.ObjectContext.MetadataWorkspace.ImplicitLoadAssemblyForType(typeof(TResultType), Assembly.GetCallingAssembly());
            var clrOfType = typeof(TResultType);
            EdmType ofType;
            if (!QueryState.ObjectContext.MetadataWorkspace.GetItemCollection(DataSpace.OSpace).TryGetType(
                clrOfType.Name, clrOfType.NestingNamespace() ?? string.Empty, out ofType)
                || !(Helper.IsEntityType(ofType) || Helper.IsComplexType(ofType)))
            {
                var message = Strings.ObjectQuery_QueryBuilder_InvalidResultType(typeof(TResultType).FullName);
                throw new EntitySqlException(message);
            }
            return new ObjectQuery<TResultType>(EntitySqlQueryBuilder.OfType(QueryState, ofType, clrOfType));
        }
public ObjectQuery < TResultType > OfType < TResultType > ( ) { if ( IsLinqQuery ( this ) ) { return ( ObjectQuery < TResultType > ) Queryable . OfType < TResultType > ( this ) ; } QueryState . ObjectContext . MetadataWorkspace . ImplicitLoadAssemblyForType ( typeof ( TResultType ) , Assembly . GetCallingAssembly ( ) ) ; var clrOfType = typeof ( TResultType ) ; EdmType ofType ; if ( ! QueryState . ObjectContext . MetadataWorkspace . GetItemCollection ( DataSpace . OSpace ) . TryGetType ( clrOfType . Name , clrOfType . NestingNamespace ( ) ?? string . Empty , out ofType ) || ! ( Helper . IsEntityType ( ofType ) || Helper . IsComplexType ( ofType ) ) ) { var message = Strings . ObjectQuery_QueryBuilder_InvalidResultType ( typeof ( TResultType ) . FullName ) ; throw new EntitySqlException ( message ) ; } return new ObjectQuery < TResultType > ( EntitySqlQueryBuilder . OfType ( QueryState , ofType , clrOfType ) ) ; }
Limits the query to only results of a specific type.
Limits the query to only results of a specific type .
// SQLPUDT 484477: Make sure TResultType is loaded. // Retrieve the O-Space type metadata for the result type specified. If no // metadata can be found for the specified type, fail. Otherwise, if the // type metadata found for TResultType is not either an EntityType or a // ComplexType, fail - OfType() is not a valid operation on scalars, // enumerations, collections, etc.
A new  instance that is equivalent to the original instance with OFTYPE applied.
A new instance that is equivalent to the original instance with OFTYPE applied .
The type specified is not valid.
The type specified is not valid .
typeparam
The type of the  returned when the query is executed with the applied filter.
The type of the returned when the query is executed with the applied filter .