Book Image

Entity Framework 4.1: Expert's Cookbook

By : Devlin Liles , Tim Rayburn
Book Image

Entity Framework 4.1: Expert's Cookbook

By: Devlin Liles , Tim Rayburn

Overview of this book

<p>Entity Framework 4.1 allows us to dive into the world of data access without having to write SQL statements. With the power to shape data access by your object model comes questions and this book holds the answers.</p> <p>Entity Framework 4.1: Expert's Cookbook holds many examples to help guide you through tough technical decisions and avoid technical landmines. The book will guide you from just using Entity Framework to enhancing the data access wizard.</p> <p>This book starts with examples that require some familiarity of object relational mappers, and then moves on to more advanced tasks. You will be guided through complex mapping scenarios, query definition, reusability, integration with other technologies, and architectural management. The approach is step-by-step and test driven so that it is focused as much as possible on solving problems and getting the most out of the time spent working through the book.</p> <p>Entity Framework 4.1: Expert's Cookbook is a must have for any .NET developer who uses Entity Framework, and wants better, cleaner, and more maintainable code.</p>
Table of Contents (15 chapters)
Entity Framework 4.1: Expert's Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

In this book, we attempt to bring together the best practices around using Entity Framework in a test-first manner, focusing on the architectural separation of concerns, and testability at all times. Throughout the book, we focus on ways to ensure the best quality of performance from your data layer, providing you with measurable ways to test performance, to reviewing SQL statements generated by Entity Framework.

What this book covers

Chapter 1, Improving Entity Framework in the Real World, describes how to use code first, establish repository and unit of work patterns, and test your queries.

Chapter 2, Understanding Fluent Configuration API, goes into detail on how to manage configuration mappings between your entities and your database.

Chapter 3, Handling Validation in Entity Framework, discusses validation from the simple to the complex, and how to integrate that with an ASP.NET MVC user interface.

Chapter 4, Working with Transactions and Stored Procedures, provides best practices around using Stored Procedures in your environment while maintaining separation of concerns between the database and Entity Framework.

Chapter 5, Improving Entity Framework with Query Libraries, begins the ground work of separating your queries in a testable, composable manner.

Chapter 6, Improving Complex Queries Scenarios, opens by discussing dynamic sorting and grouping and closes with a complete Specification pattern implementation.

Chapter 7, Using Concurrent and Parallel Processing, describes the challenges faced in highly concurrent applications, and when managing multiple database contexts.

Chapter 8, Improving Entity Framework with Complex Business Scenarios, discusses some of the more difficult business requests, such as handling soft deletes, capturing audit data, and refreshing entities from the database on save.

What you need for this book

In order to use this book you will need access to Visual Studio 2010, Express Edition or above. There are a small number of recipes that discuss load testing, which require the Ultimate Edition, but those are specifically called out in those recipes.

Who this book is for

This book is intended for professional software developers who advocate, or are interested in, test driven development and Entity Framework. It assumes basic knowledge of a test runner, in this case MS Test, the integrated test runner of Visual Studio 2010.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

{
  [TestClass]
  public class QueryTests
  {

    [TestMethod]
    public void ShouldReturnRecordsFromTheDatabase()
    {
      //Arrange
      var init = new Initializer();
      var context = new 
        BlogContext(Settings.Default.BlogConnection);
      init.InitializeDatabase(context);
      IBlogRepository repo = new BlogRepository(context);
            

      //Act
      var items = repo.Set<Blog>().FilterByBlogName("Test");
            
      //Assert
      Assert.AreEqual(2, items.Count());
    }
  }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

{
  public class Blog
  {
    public int Id { get; set; }
    public DateTime Creationdate { get; set; }
    public string ShortDescription { get; set; }
    public string Title { get; set; }
    public double Rating { get; set; }
  }
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Open the Improving Collection Property Validation solution in the included source code examples."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.