Example #1
0
        public void Load_DbCfg()
        {
            var cfg  = DbConfigure.GetConfigure("YmtUserContext");
            var conn = @"Data Source=YMT-LIGUO\LIGUO;Initial Catalog=Ymt_Test_7;Persist Security Info=True;User ID=sa;Password=123@#$123asd";

            Assert.AreEqual(conn, cfg.Connection);
        }
Example #2
0
        public YmtSystemDbContext CreateContext(Type storageContextType)
        {
            var contextType      = storageContextType;
            var contextAttribute = contextType.GetCustomAttributes(false).OfType <StoreContextAttribute>().SingleOrDefault();

            if (contextAttribute == null)
            {
                contextAttribute = new StoreContextAttribute();
            }

            var contextName = contextAttribute.StoreContextName;
            var scope       = DbConfigure.GetConfigure(contextName).Scope;

            return(YmtSystemDbContextScope <YmtSystemDbContext> .GetEntity(() => (YmtSystemDbContext)Activator.CreateInstance(contextType, contextName), scope));
        }
Example #3
0
        public TContext CreateContext <TContext>(Func <string, TContext> factory) where TContext : YmtSystemDbContext
        {
            var contextType = typeof(TContext);

            var contextAttribute = contextType.GetCustomAttributes(false).OfType <StoreContextAttribute>().SingleOrDefault();

            if (contextAttribute == null)
            {
                contextAttribute = new StoreContextAttribute();
            }

            var contextName = contextAttribute.StoreContextName;
            var scope       = DbConfigure.GetConfigure(contextName).Scope;

            return(YmtSystemDbContextScope <TContext> .GetEntity(() => factory(contextName), scope));
        }
Example #4
0
 public static DbConnection Builder(DbConfigure cfg)
 {
     try
     {
         YmtSystemAssert.AssertArgumentNotNull(cfg, "DbConfigure 不能为空");
         var factory    = DbProviderFactories.GetFactory(cfg.Provider);
         var connection = factory.CreateConnection();
         connection.ConnectionString = cfg.Connection;
         //LocalFileCfg.GetLocalCfgValueByFile<string>("db.cfg", ValueFormart.CJsv, @"Data Source=YMT-LIGUO\LIGUO;Initial Catalog=Ymt_Test_7;Persist Security Info=True;User ID=sa;Password=123@#$123asd");
         //TODO:这里可以设置其他链接属性
         return(connection);
     }
     catch (Exception ex)
     {
         YmatouLoggingService.Error("创建链接对象异常 {0}", ex.ToString());
         throw;
     }
 }