Click here to Skip to main content
15,897,891 members
Articles / Programming Languages / C# 4.0

Entity Framework - Second Level Caching with DbContext

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
6 Aug 2012CPOL6 min read 105.6K   2.6K   48  
How to enable second level caching in the Entity Framework when using DbContext.
using System;
using System.Collections.Generic;

namespace SecondLevelCaching.Data.Models
{
    public class Employee
    {
        public Employee()
        {
            this.Employees1 = new List<Employee>();
            this.Orders = new List<Order>();
            this.Territories = new List<Territory>();
        }

        public int EmployeeID { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public string Title { get; set; }
        public string TitleOfCourtesy { get; set; }
        public Nullable<System.DateTime> BirthDate { get; set; }
        public Nullable<System.DateTime> HireDate { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string HomePhone { get; set; }
        public string Extension { get; set; }
        public byte[] Photo { get; set; }
        public string Notes { get; set; }
        public Nullable<int> ReportsTo { get; set; }
        public string PhotoPath { get; set; }
        public virtual ICollection<Employee> Employees1 { get; set; }
        public virtual Employee Employee1 { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
        public virtual ICollection<Territory> Territories { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions