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

Implementing the specification pattern


In this recipe, we will be implementing a specification pattern on top of Entity Framework and Repository Pattern to leverage maximum reuse without surfacing queryable objects to the consuming developers.

Getting ready

We will be using the NuGet package manager to install the Entity Framework 4.1 assemblies.

The package installer can be found at http://nuget.org.

We will also be using a database for connecting to and updating data.

Open the Improving Complex Query Testing solution in the included source code examples.

How to do it...

Carry out the following steps in order to accomplish this recipe.

  1. We start by writing a test which will query the database with a predefined specification. Use the following code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using BusinessLogic;
    using DataAccess.Queries;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Rhino.Mocks;
    using DataAccess;
    using BusinessLogic.QueryObjects;
    using Test.Properties...