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
    }
}

相关文章:

  • 2021-04-27
  • 2021-12-12
  • 2021-06-18
  • 2021-08-23
  • 2022-12-23
  • 2022-01-08
  • 2021-07-27
猜你喜欢
  • 2022-01-08
  • 2021-06-12
  • 2021-06-14
  • 2021-10-21
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案