You maintain a database on an instance of SQL Server 2008. Your database contains the following tables and relationships:
Your development team uses Visual Studio 2008 and object-oriented programming (OOP) techniques to create applications that access data in your database. You want to reduce the coding complexity for developers writing data access code, and minimize application changes required when the database schema changes.
You want developers to be able to instantiate Employee and Course objects and access column data using object properties.
What should you do?
A. Create a data model using the Entity Framework that includes an entity for each database table and an association for each FOREIGN KEY constraint.
B. Create a data model using the Entity Framework that includes the Employee and Course entities.
C. Create application-specific views and use INSTEAD OF triggers to perform any update or delete operations.
D. Create stored procedures that developers must use for data access.
Correct Answer: B
Explanation/Reference:
The Entity Framework allows you to create data models that allow developers to query a conceptual model without being concerned with the underlying database schema. An Entity Data Model (EDM) abstracts the conceptual model from the physical database schema. An EDM contains a conceptual model, a logical storage model, and mappings between the two models, which are each stored in special XML files. The conceptual model is stored in a conceptual schema definition language (.csdl) file. The storage model is stored in a storage schema definition language (.ssdl) file. The mappings are stored in a mapping specification language (.msl) file. The EDM consists of entities and relationships. Entities can be exposed as objects, so they can have properties and be instantiated in application code.
Relationships can be defined that relate entities in the conceptual model and support inheritance between entities.
Creating entities in the EDM that represent logical business entities simplifies the conceptual view of the underlying table structures. For example, in this scenario, you would have an Employee entity and a Course entity. An Employee object might have a Department property that is the employee’s department, and a Courses property that is a collection containing the courses that the employee has previously taken. You would also have aCourse entity. A Course object might have a collection of attendees as one of its properties. The Entity Framework uses the XML files representing the model to translate the operations performed on the data model to operations against the respective tables in the underlying data source. If the database schema changes, the .ssdl and .msl files can be changed to reflect changes in the data model without requiring changes to either the conceptual model or the application code. The Entity Framework provides a special query language called Entity SQL. Entity SQL is similar to SQL, but has different syntax. Developers may use Entity SQL to write data access code against the conceptual model.
You should not create a data model using the Entity Framework that includes an entity for each database table and an association for each FOREIGN KEY constraint. An EDM is intended to abstract the conceptual model from the underlying database structure.
You should not create application-specific views and use INSTEAD OF triggers to perform update or delete operations, or create stored procedures that developers must use for data access. Views, INSTEAD OF triggers, and stored procedures are often used to increase performance, prevent SQL injection attacks, or centralize or hide SQL code. However, database schema changes may still require that these constructs and application code be modified. In this scenario, you wanted to minimize the impact if the database schema changed.