// @nuget: Z.EntityFramework.Classic
using System;
using System.Linq;
using System.Data.Entity;
public class Program
{
public static void Main()
GenerateData();
using (var context = new EntityContext())
// The first call perform a database round trip
var countries1 = context.Countries.Cache().ToList();
// Subsequent calls will take the value from the memory instead
var countries2 = context.Countries.Cache().ToList();
FiddleHelper.WriteTable(countries2);
}
public static void GenerateData()
context.Countries.Add(new Country() { Name ="Customer_A" });
context.Countries.Add(new Country() { Name ="Customer_B" });
context.Countries.Add(new Country() { Name ="Customer_C" });
context.SaveChanges();
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Country> Countries { get; set; }
public class Country
public int CountryID { get; set; }
public string Name { get; set; }