Entity Framework 4

Overview

Entity Framework (EF) 4 is an object‑relational mapping (ORM) framework that enables .NET developers to work with relational data using domain-specific objects. EF 4 ships as part of the .NET Framework 3.5 Service Pack 1 and introduces a range of improvements over the initial release.

Key Features

  • Support for POCO (Plain Old CLR Objects) and self‑tracking entities.
  • Improved LINQ to Entities performance and query translation.
  • Support for complex types, enums and inheritance mapping strategies.
  • Lazy loading and eager loading capabilities.
  • Enhanced designer experience with Model First workflow.
  • Better integration with Visual Studio 2008 SP1.

System Requirements

Operating SystemWindows XP SP2 or later, Windows Server 2003 SP2 or later
.NET Framework.NET Framework 3.5 SP1 (including EF 4)
IDEVisual Studio 2008 SP1 or later

Getting Started

  1. Install .NET Framework 3.5 SP1 which includes EF 4.
  2. Create a new Console Application or ASP.NET Web Application project in Visual Studio.
  3. Right‑click the project, choose Add → New Item → ADO.NET Entity Data Model.
  4. Select “EF Designer from database” or “Empty EF Designer Model” to generate the EDMX file.
  5. Configure the connection string in App.config or Web.config.
  6. Start querying the model using LINQ or Entity SQL.

Code Sample

Below is a simple example that demonstrates how to query a Products table using LINQ to Entities.

// Assuming the EDMX generated context is named SampleContext
using (var ctx = new SampleContext())
{
    var cheapProducts = ctx.Products
                         .Where(p => p.Price < 20)
                         .OrderBy(p => p.Name)
                         .ToList();

    foreach (var p in cheapProducts)
    {
        Console.WriteLine($"{p.ProductID}: {p.Name} - ${p.Price}");
    }
}

Additional Resources