Udostępnij za pośrednictwem


DefiningQuery Element (SSDL)

The DefiningQuery element in store schema definition language (SSDL) allows you to execute a SQL statement directly in the underlying database. The DefiningQuery element is commonly used like a database view, but the view is defined in the storage model instead of the database. The view defined in a DefiningQuery element can be mapped to an entity type in the conceptual model through an EntitySetMapping element. These mappings are read-only. For more information, see How to: Add a Defining Query.

The following SSDL syntax shows the declaration of an EntitySet followed by the DefiningQuery element that contains a query used to retrieve the view.

<Schema> 
    <EntitySet Name="Tables" EntityType="Self.STable"> 
        <DefiningQuery> 
          SELECT  TABLE_CATALOG, 
                  'test' as TABLE_SCHEMA, 
                  TABLE_NAME 
          FROM    INFORMATION_SCHEMA.TABLES
        </DefiningQuery> 
    </EntitySet> 
</Schema>

You can use stored procedures in the Entity Framework to enable read-write scenarios over views. You can use either a data source view or an Entity SQL view as the base table for retrieving data and for change processing by stored procedures.

You can use the DefiningQuery element to target Microsoft SQL Server Compact 3.5. Though SQL Server Compact 3.5 does not support stored procedures, you can implement similar functionality with the DefiningQuery element. Another place where it can be useful is in creating stored procedures to overcome a mismatch between the data types used in the programming language and those of the data source. You could write a DefiningQuery that takes a certain set of parameters and then calls a stored procedure with a different set of parameters, for example, a stored procedure that deletes data.

See Also

Concepts

Entity Framework Overview
SSDL Specification

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools