- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Text;
- using Dulei.Model;
- namespace Dulei.DAL
- {
- public class EFDbcontextFactory
- {
- public static DbContext GetcurrentDbcontext()
- {
- //可以直接对Model模型进行切换。只要更改DataModelContainer()
- return new DataModelContainer();
- }
- }
- }
改
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Text;
using Dulei.Model;
namespace Dulei.DAL
{
public class EFDbcontextFactory
{
public static DbContext GetcurrentDbcontext()
{
DbContext db = (DbContext) CallContext.GetData("Dbcontext");
if (db==null)
{
db = new DataModelContainer();
CallContext.SetData("Dbcontext",db);
}
//也可以使用HttpContext是一样的
return db;
}
}
}