Book Image

Code-First Development with Entity Framework

By : Sergey Barskiy
Book Image

Code-First Development with Entity Framework

By: Sergey Barskiy

Overview of this book

<p>Entity Framework Code-First enables developers to read and write data in a relational database system using C# or VB.NET. It is Microsoft's answer to demand for an ORM from .NET developers.</p> <p>This book will help you acquire the necessary skills to program your applications using Entity Framework. You will start with database configuration and learn how to write classes that define the database structure. You will see how LINQ can be used with Entity Framework to give you access to stored data. You will then learn how to use Entity Framework to persist information in a Relational Database Management System. You will also see how you can benefit from writing ORM-based .NET code. Finally, you will learn how Entity Framework can help you to solve database deployment problems using migrations.</p>
Table of Contents (15 chapters)
Code-First Development with Entity Framework
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Entity Framework architecture


Entity Framework is built on the provider architecture. When a developer creates a LINQ query using C# or VB.NET, the framework engine in conjunction with a provider converts it into an actual SQL statement that is sent to the database. Any given provider is the link between Entity Framework and a specific RDBMS that this provider is written for. In this book, we will concentrate on the Code-First approach, but this architecture is used in the Database First approach as well. Once the provider executes the final SQL command, its results are materialized into .NET objects by Entity Framework. Data reader is used for this purpose. It is important to understand that Entity Framework is still built on top of ADO.NET, thus it is uses concepts such as connection, command, and data reader. When it comes to data persistence, in other words; insert, update, and delete functionalities, the flow is as follows: In the case of inserts, a developer adds an instance of an entity class to the context. Similarly, an entity previously added to the context can be flagged as changed or deleted, causing the update or delete SQL statement to be executed against the database, respectively. Entity Framework examines the state of each object in its context, using the provider again to create an RDBMS-specific insert, update, or delete command.