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<Category> Categories { get; set; }
    public DbSet<Product> Products { get; set; }
}

public void UseProducts()
{
    using (var context = new ProductContext())
    {     
        // Perform data access using the context
    }
}
posted @ 2020-07-16 09:04  Lee.Yan  阅读(66)  评论(0编辑  收藏