Apress Access

Entity Framework 6 Recipes

2nd Edition

By Brian Driscoll , Nitin Gupta , Robert Vettor , Zeeshan Hirani , Larry Tenny

  • eBook Price: $34.99
Buy eBook Buy Print Book
Entity Framework 6 Recipes teaches the core concepts of Entity Framework through a broad range of clear and concise solutions to everyday data access tasks.

Full Description

  • Add to Wishlist
  • ISBN13: 978-1-4302-5788-2
  • 548 Pages
  • User Level: Intermediate to Advanced
  • Publication Date: November 4, 2013
  • Available eBook Formats: EPUB, MOBI, PDF

Related Titles

  • Pro C# 5.0 and the .NET 4.5 Framework
  • Pro ASP.NET MVC 5
  • Pro ASP.NET Web API
  • Pro Asynchronous Programming with .NET
  • Mobile ASP.NET MVC 5
  • Beginning SQL Server R Services
  • Securing SQL Server
  • Practical Microsoft Visual Studio 2015
  • Develop Microsoft HoloLens Apps Now
  • ASP.NET MVC with Entity Framework and CSS
Full Description

Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's model-centric, data-access platform for the .NET Framework and ASP.NET development. With this book, you will learn the core concepts of Entity Framework through a broad range of clear and concise solutions to everyday data access tasks. Armed with this experience, you will be ready to dive deep into Entity Framework, experiment with new approaches, and develop ways to solve even the most difficult data access challenges. If you are a developer who likes to learn by example, then this is the right book for you.

  • Gives ready-to-use, real-world recipes to help you with everyday tasks
  • Places strong focus on DbContext and the Code First approach
  • Covers new features such as Asynch Query and Save, Codebased Configuration, Connection Resiliency, Dependency Resolution, and much more

What you’ll learn

  • Implement basic data access design patterns using Entity Framework.
  • Seamlessly model your solutions across both code and data.
  • Provide data access to Windows 8 and Metro applications.
  • Integrate with WCF Data Services
  • Improve data access performance.
  • Simplify and reduce your code through data binding.

Who this book is for

Entity Framework 6 Recipes is for anyone learning Microsoft’s Entity Framework—Microsoft’s primary data access platform in the .NET Framework. If you have ever struggled to learn a new technology, programming model, or way of doing something, you know how helpful simple and real-world examples can be. For the beginning developer, this book provides concrete examples for common data access tasks. For developers having experience with previous Microsoft data access platforms, this book provides a task-by-task mapping between previous approaches and the patterns used in Entity Framework.

Table of Contents

Table of Contents

  1. Getting Started with Entity Framework
  2. Entity Data Modeling Fundamentals
  3. Querying an Entity Data Model
  4. Using Entity Framework in ASP.NET
  5. Loading Entities and Navigation Properties
  6. Beyond the Basics with Modeling and Inheritance
  7. Working with Object Services
  8. Plain Old CLR Objects
  9. Using the Entity Framework in N-Tier Applications
  10. Stored Procedures
  11. Functions
  12. Customizing Entity Framework Objects
  13. Improving Performance
  14. Concurrency
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.


If you think that you've found an error in this book, please let us know by emailing to editorial@apress.com . You will find any confirmed erratum below, so you can check if your concern has already been addressed.

On page 24:


does not work. It only creates an album record without artists linked. One possible solution is making the reverse linking. For example:


On page 25:

Output of Recipe3 is
Artists and their albums...
Alan Jackson
Live at Texas Stadium

Albums and their artists...
Alan Jackson
Live at Texas Stadium
Alan Jackson
Honkytonk University

I have to change the code to add artists to album before adding a new album to the context (not the other way round).
// add an album for two artists
var artist1 = new Artist { FirstName = "Tobby", LastName = "Keith" };
var artist2 = new Artist { FirstName = "Merle", LastName = "Haggard" };
var album = new Album { AlbumName = "Honkytonk University" };

On page 26:
using (var context = new EF6RecipesContext())
var order = new Order { OrderId = 1,
OrderDate = new DateTime(2010, 1, 18) };
var item = new Item { SKU = 1729, Description = "Backpack",
Price = 29.97M };
var oi = new OrderItem { Order = order, Item = item, Count = 1 };

item = new Item { SKU = 2929, Description = "Water Filter",
Price = 13.97M };
oi = new OrderItem { Order = order, Item = item, Count = 3 };
item = new Item { SKU = 1847, Description = "Camp Stove",
Price = 43.99M };
oi = new OrderItem { Order = order, Item = item, Count = 1 };

//should add this in order to make the source code to work--->order.OrderItems.Add(oi);

On page 29:

I have to replace

public List<PictureCategory> Subcategories { get; set; }


public virtual List<PictureCategory> Subcategories { get; set; }

in order to list the children

On page 30:
public PictureContext() : base("name=EF6CodeFirstRecipesContext")

must be:

public EF6RecipesContext() : base("name=EF6CodeFirstRecipesContext")

On page 31:
In order to achive the expected result, is necessary to change:




On page 52:
Figures are mixed up. Caption for 2.23 needs to be 2.24 and vice versa.

On page 74:
The following sentence does not work because you're not using T-SQL.

var employees = context.Database.SqlQuery<Employee>(esql);

You are running an Entity SQL statement which uses ObjectContext instead of DbContext.

var employees = ((IObjectContextAdapter)context).ObjectContext.CreateQuery<Employee>(esql);

On page 161-162:

You need to disable explicit loading because otherwise the example doesn't show his purpose

// explicitly disable lazy loading
context.Configuration.LazyLoadingEnabled = false;

The output should be the following:

Executive Suites for Grand Seasons Hotel with reservations

Executive Suite 14 is $299,95 per night
Current reservations are:
18/01/2010 thru 28/01/2010 (Bill Meyers)
12/03/2010 thru 14/03/2010 (Roberta Jones)
Press <enter> to continue...

On page 172:

The output of the code is wrong. in Listing 5-31.
Line 4 should say:

"Dr. Steven Mills was explicitly loaded"


"Dr. Steven Mills was lazy loaded"

On page 176:

Listing 5-36.
AddObject no longer exists.

the last section should read


    1. PHP Objects, Patterns, and Practice


      View Book

    2. Beginning Android 3D Game Development


      View Book

    3. Troubleshooting Oracle Performance


      View Book

    4. Beginning Amazon Web Services with Node.js


      View Book