Beispiel #1
0
        public static TkDbContext CreateDefault()
        {
            ISupportDbContext support = GetSupport();
            DbContextConfig   config  = support.Default;

            TkDebug.AssertNotNull(config, "AppSetting中没有配置Default的DbContext", support);
            return(config.CreateDbContext());
        }
Beispiel #2
0
        public static TkDbContext CreateDbContext(string name)
        {
            TkDebug.AssertArgumentNullOrEmpty(name, "name", null);

            ISupportDbContext support = GetSupport();
            DbContextConfig   config  = support.GetContextConfig(name);

            TkDebug.AssertNotNull(config, string.Format(ObjectUtil.SysCulture,
                                                        "AppSetting中没有配置名称为{0}的DbContext", name), support);

            return(config.CreateDbContext());
        }
Beispiel #3
0
        public static DbContextConfig Create(string name, string sqlProvider,
                                             string dbProvider, string connectionString)
        {
            TkDebug.AssertArgumentNullOrEmpty(sqlProvider, "sqlProvider", null);
            TkDebug.AssertArgumentNullOrEmpty(dbProvider, "dbProvider", null);
            TkDebug.AssertArgumentNullOrEmpty(connectionString, "connectionString", null);

            TkDebug.ThrowIfNoGlobalVariable();

            DbContextConfig config = new DbContextConfig
            {
                Name             = name,
                SqlProvider      = sqlProvider,
                DbProvider       = dbProvider,
                ConnectionString = connectionString
            };

            return(config);
        }
Beispiel #4
0
 internal TkDbContext(DbContextConfig contextConfig, IDbConnection connection)
 {
     fContextConfig    = contextConfig;
     DbConnection      = connection;
     fCreateConnection = false;
 }
Beispiel #5
0
 internal TkDbContext(DbContextConfig contextConfig)
 {
     fContextConfig    = contextConfig;
     DbConnection      = contextConfig.CreateConnection();
     fCreateConnection = true;
 }