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

Creating the Entity Data Model


Let's now start by creating our POCO entities one by one. We will first create all the entity classes with all the properties that we want in their respective entities. Once the entity classes are ready, we will take a look at how to implement relationships between the entities, and start adding the navigation properties in the entity classes.

Creating the entity classes

Let's take a look at all the entities needed one by one.

The User entity

First, let's create the entity class to hold the User details. The User entity is responsible for holding the data that is needed to authenticate the user. The following code shows what the User entity would look like:

public partial class User
{
    public int Id { get; set; }
    public string Email { get; set; }
    public bool EmailConfirmed { get; set; }
    public string PasswordHash { get; set; }
    public string SecurityStamp { get; set; }
    public string UserName { get; set; }
}

The preceding code shows the User...