你的位置:首页 > ASP.net教程

[ASP.net教程]MVC 创建线程内的db单例


 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using LSUnion.Site.Models; 6  7 namespace LSUnion.Site.WebHelper 8 { 9   using System.Runtime.Remoting.Messaging;10   public class Factory11   {12     public static LSUnionEntities GetDbContext()13     {14       object db = CallContext.GetData("LSUnionEntities");15       if (db==null)16       {17         db = new LSUnionEntities();18         CallContext.SetData("LSUnionEntities",db);19       }20       return db as LSUnionEntities;21     }22   }23 }