1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data.Entity;  
  4. using System.Linq;  
  5. using System.Runtime.Remoting.Contexts;  
  6. using System.Runtime.Remoting.Messaging;  
  7. using System.Text;  
  8. using Dulei.Model;  
  9.   
  10.   
  11. namespace Dulei.DAL  
  12. {  
  13.      public class EFDbcontextFactory  
  14.     {  
  15.          public static DbContext GetcurrentDbcontext()  
  16.          {  
  17.              DbContext db = (DbContext) CallContext.GetData("Dbcontext");  
  18.              if (db==null)  
  19.              {  
  20.                  db = new DataModelContainer();  
  21.                  CallContext.SetData("Dbcontext",db);  
  22.              }  
  23.              //也可以使用HttpContext是一样的  
  24.              return db;  
  25.          }  
  26.     }  

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-11-03
  • 2022-01-01
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2021-05-06
  • 2021-11-28
  • 2021-07-03
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案