欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

EntityFramework 6 Tips

程序员文章站 2022-07-09 19:22:20
When working with Web applications, use a context instance per request. Install-Package EntityFramework -Version using System.Data.Entity; public clas ......

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