Querying a Conceptual Model

The ADO.NET Entity Framework enables you to query a conceptual model. The Entity Framework supports the following kinds of queries against a conceptual model:

Query Type Description

Language Integrated Query (LINQ)

LINQ to Entities enables you to execute LINQ queries against entity data by using language-specific query operators. For more information, see LINQ to Entities.

Entity SQL

Entity SQL is a storage-independent query language that is similar to SQL. Entity SQL allows you to query entity data, either as objects or in a tabular form. You should consider using Entity SQL in the following cases:

  • When a query must be dynamically constructed at runtime. In this case, you should also consider using the query builder methods of ObjectQuery instead of constructing an Entity SQL query string at runtime.

  • When you want to define a query as part of the model definition. Only Entity SQL is supported in a data model. For more information, see QueryView Element (MSL)

  • When using EntityClient to return read-only entity data as rowsets using a EntityDataReader. For more information, see EntityClient Provider for the Entity Framework.

  • If you are already an expert in SQL-based query languages, Entity SQL may seem the most natural to you.

Query builder methods

These methods of ObjectQuery enable you to construct queries that are the same as Entity SQL without having to construct a query string. Because these methods always return an ObjectQuery, you can build queries by calling methods in series or use them to extend an Entity SQL query. Some methods, such as Where and OrderBy, take Entity SQL fragments as parameters. Query builder methods can be followed by certain LINQ standard query operators. For more information, see Query Builder Methods.

The topics in this section describe how to use the ObjectQuery class to query a conceptual model. For more information about executing LINQ queries against a conceptual model, see Queries in LINQ to Entities.

In This Section

Object Queries

Loading Related Objects

Query Builder Methods

Directly Executing Store Commands

How to: Execute a Query that Returns Entity Type Objects

How to: Execute a Parameterized Query

How to: Navigate Relationships Using Navigation Properties

How to: Use Query Paths to Shape Results

How to: Explicitly Load Related Objects

How to: Use Lazy Loading to Load Related Objects

How to: Call a User-Defined Function

How to: Filter Data

How to: Sort Data

How to: Group Data

How to: Aggregate Data

How to: Execute a Query that Returns Anonymous Type Objects

How to: Execute a Query that Returns a Collection of Primitive Types

How to: Return a Specific Object Using its Key

How to: Query Related Objects in an EntityCollection

How to: Order the Union of Two Queries

How to: Page Through Query Results

How to: View the Store Commands

How to: Remove Duplicate Elements From Query Results

How to: Execute a Query Using a Stored Procedure with In and Out Parameters

How to: Query Complex Types

How to: Query Objects with Multiple Entity Sets per Type

How to: Query an Entity Mapped to Separate Tables

How to: Directly Execute Commands Against the Data Source

See Also


Working with Objects
EntityClient Provider for the Entity Framework
Queries in LINQ to Entities
Entity Framework Resources
Defining and Managing Relationships

Other Resources

Sample Applications