EntityFramework 6 Tips

When working with Web applications, use a context instance per request.

Install-Package EntityFramework -Version

using System.Data.Entity;
public class Category{}
public class Product{}
public class ProductContext : DbContext
{
    public DbSet Categories { get; set; }
    public DbSet Products { get; set; }
}

public void UseProducts()
{
    using (var context = new ProductContext())
    {     
        // Perform data access using the context
    }
}

你可能感兴趣的:(EntityFramework 6 Tips)