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

Implementing optimistic concurrency using Entity Framework


There are a number of ways in which we can implement optimistic concurrency using Entity Framework. In this section, we will take a look at a few of them.

Let's use a simple database to test the concurrency issues. Let's have a single Employee table for our testing purpose. The Employee table will contain only three fields: ID, EmployeeName, and Salary. The generated Entity Data Model for this database will look like the following:

The Entity Data Model for the sample application

Let's now try to see how we can implement optimistic concurrency using Entity Framework.

Entity Framework's default concurrency

Before we do anything explicitly, let's see how Entity Framework handles concurrency by default. Let's say we have our application designed to update the Salary value of an employee. Let's implement a function to retrieve the values for the employee from the database and another to update the Employee data in the database:

// Lets fetch...