EntityFramework 6 Tips

2022-10-22,

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

《EntityFramework 6 Tips.doc》

下载本文的Word格式文档,以方便收藏与打印。