标签:
//职责:确保一个请求共用一个上下文
public class DataBaseContextFactory
{
//返回基类,这样就可以随意做到切换上下文了
public static DbContext GetDataTabelContext()
{
//共用一个请求上下文实例
DbContext dbcontext = CallContext.GetData("DbContext") as DbContext;
if (dbcontext == null)
{
dbcontext = new Entities();
CallContext.SetData("DbContext", dbcontext);
}
return dbcontext;
}
}
标签:
原文地址:http://www.cnblogs.com/it-xcn/p/5746345.html