Partager via


Query an Entity Data Model (Application Scenarios)

The ADO.NET Entity Framework enables you to query entity data. The Entity Framework supports the following kinds of queries against entity data:

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 Overview.

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 (EntitySetMapping)

  • 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, such as FirstOrDefault. For more information, see Query Builder Methods (Entity Framework).

The following links are to topics relevant to this scenario. For more Entity Framework scenarios, see Application Scenarios (Entity Framework).

See Also

Concepts

Entity Data Model Inheritance (Application Scenarios)
Entity Framework Resources

Other Resources

Application Scenarios (Entity Framework)
Programming Guide (Entity Framework)
Sample Applications (Entity Framework)