public class ObjectContextFactory { private static CIK_NewsEntities context; public static DbContext GetContext() { //从CallContext数据槽中获取EF上下文 context = CallContext.GetData(typeof(ObjectContextFactory).FullName) as CIK_NewsEntities; if (context==null) { //如果CallContext数据槽中没有EF上下文,则创建EF上下文,并保存到CallContext数据槽中 context = new CIK_NewsEntities(); CallContext.SetData(typeof(ObjectContextFactory).FullName, context); } return context; } }