Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 7, 2023
1 parent c603d07 commit 2c42ee6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/net60_webapi/DB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class DB
.UseAutoSyncStructure(true)
.Build());
Console.WriteLine(fsql.Ado.ConnectionString);
Console.WriteLine(fsql.Ado.ConnectionString);
using (fsql.Change(DbEnum.db2))
{
Console.WriteLine(fsql.Ado.ConnectionString);
Expand Down
13 changes: 8 additions & 5 deletions examples/net60_webapi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,31 @@
void test()
{
var fsql = new FreeSqlCloud2();
fsql.Register(DbEnum2.ojDb3D, () =>

Console.WriteLine(fsql.Ado.DataType);

fsql.Register("ojDb3D", () =>
new FreeSqlBuilder()
.UseConnectionFactory(DataType.PostgreSQL, () => null)
.UseNameConvert(NameConvertType.ToLower).Build());
fsql.Register(DbEnum2.ChDb, () =>
fsql.Register("ChDb", () =>
new FreeSqlBuilder()
.UseConnectionFactory(DataType.Oracle, () => null)
.UseNameConvert(NameConvertType.ToUpper).Build());

Console.WriteLine(fsql.Ado.DataType);
using (fsql.Change(DbEnum2.ChDb))
using (fsql.Change("ChDb"))
{
Console.WriteLine(fsql.Ado.DataType);
using (fsql.Change(DbEnum2.ojDb3D))
using (fsql.Change("ojDb3D"))
{
Console.WriteLine(fsql.Ado.DataType);
}
Console.WriteLine(fsql.Ado.DataType);
}
Console.WriteLine(fsql.Ado.DataType);
}
public class FreeSqlCloud2 : FreeSqlCloud<DbEnum2>
public class FreeSqlCloud2 : FreeSqlCloud<string>
{
public FreeSqlCloud2() : base(null) { }
public FreeSqlCloud2(string distributekey) : base(distributekey) { }
Expand Down
22 changes: 14 additions & 8 deletions src/FreeSql.Cloud/FreeSqlCloud.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using FreeSql.Cloud.Saga;
using FreeSql.Cloud.Abstract;
using FreeSql.Cloud.Model;
using FreeSql.Cloud.Saga;
using FreeSql.Cloud.Tcc;
using FreeSql.Internal;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Data;
using System.Threading;
using FreeSql.Cloud.Model;
using FreeSql.Cloud.Abstract;

namespace FreeSql
{
//public class FreeSqlCloud : FreeSqlCloud<string> { }
public partial class FreeSqlCloud<TDBKey> : FreeSqlCloudBase, IFreeSql
//public class FreeSqlCloud : FreeSqlCloud<string> { }
public partial class FreeSqlCloud<TDBKey> : FreeSqlCloudBase, IFreeSql
{
internal override string GetDBKey() => _dbkey.ToInvariantCultureToString();
public override IFreeSql Use(DBKeyString dbkey) => Use((TDBKey)typeof(TDBKey).FromObject(dbkey?.ToString()));
Expand Down Expand Up @@ -55,7 +53,15 @@ public TDBKey DBKey
internal TDBKey _dbkeyMaster;

internal AsyncLocalAccessor<TDBKey> _dbkeyCurrent;
internal TDBKey _dbkey => _dbkeyCurrent.Value;
internal TDBKey _dbkey
{
get
{
var val = _dbkeyCurrent.Value;
if (typeof(TDBKey) == typeof(string) && val == null) return _dbkeyMaster;
return val;
}
}
internal IFreeSql _ormMaster => _ib.Get(_dbkeyMaster);
internal IFreeSql _ormCurrent => _ib.Get(_dbkey);
internal IdleBus<TDBKey, IFreeSql> _ib;
Expand Down

0 comments on commit 2c42ee6

Please sign in to comment.