Book Image

Mastering Entity Framework

By : Rahul Rajat Singh
Book Image

Mastering Entity Framework

By: Rahul Rajat Singh

Overview of this book

<p>Data access is an integral part of any software application. Entity Framework provides a model-based system that makes data access effortless for developers by freeing you from writing similar data access code for all of your domain models.</p> <p>Mastering Entity Framework provides you with a range of options when developing a data-oriented application. You’ll get started by managing the database relationships as Entity relationships and perform domain modeling using Entity Framework. You will then explore how you can reuse data access layer code such as stored procedures and table-valued functions, and perform various typical activities such as validations and error handling. You’ll learn how to retrieve data by querying the Entity Data Model and understand how to use LINQ to Entities and Entity SQL to query the Entity Data Model.</p>
Table of Contents (19 chapters)
Mastering Entity Framework
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Comparing the development styles


Before we start looking at these development styles in detail, let's try to do a comparative analysis of these styles. It will help us in understanding these styles in detail.

The Database First approach

In a Database First approach, the main benefit that the developers have is that if the database is created, they will spend very little time writing the data access layer. The EDM can be created from the database and then we can change it as per our application needs; our data access layer is ready to use. Here are a few scenarios where the Database First approach is very useful:

  • When we are working with a legacy database.

  • When we are working in a scenario where the database design is being done by another team of DBAs, and once the database is ready, the application development starts.

  • When we are working on a data centric application, that is, the application domain model is the database itself, and it is being changed frequently to cater to new requirements. For instance, when the tables are being updated regularly and new columns are being added to it frequently then we can simply use this approach, and the application code will not break. We simply have to write the code to cater to the newly added columns.

The Model First approach

Similar to the Database First approach, in the Model First approach, we ultimately end up with the EDM. Using this EDM, we can create our conceptual model and the database. The only reason to choose the Model First approach is that we really want to use the Visual Entity Designer. There is no other strong reason to choose this approach over the other two.

The Code First approach

The Code First approach is usually helpful where all the business logic is implemented in terms of classes, and the database is simply being used as a persistence mechanism for these models. Here are a few reasons why one might want to choose the Code First approach:

  • The database is simply a persistence mechanism for the models, that is, no logic is in the database.

  • Full control over the code, that is, there is no auto-generated model and context code.

  • The database will not be changed manually. The model classes will always change and based on this, the database should change itself.