///
/// 负责创建EF上下文对象,保证线程内唯一,在一次请求内,只创建一次该对象
///
public class DbContextFactory
{
public static DbContext GetCurrentDbContext()
{
DbContext dbContext = (DbContext)CallContext.GetData("dbContext");
if(dbContext==null)
{
dbContext = new book_shopEntities();
CallContext.SetData("dbContext", dbContext);
}
return dbContext;
}
}