mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 增加 Where In 表达式解析;
- 增加 FreeSqlBuilder.UseConnectionFactory 自定义数据库连接对象的创建方法;
This commit is contained in:
parent
51494c31a2
commit
e1e3e4a3b2
@ -19,7 +19,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySqlConnector\FreeSql.Provider.MySqlConnector.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Oracle\FreeSql.Provider.Oracle.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.PostgreSQL\FreeSql.Provider.PostgreSQL.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.Sqlite\FreeSql.Provider.Sqlite.csproj" />
|
||||
|
@ -832,12 +832,16 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT sum(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -846,12 +850,16 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT min(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -860,12 +868,16 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT max(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -874,15 +886,29 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT avg(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime`
|
||||
FROM `tb_topic` a
|
||||
WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
||||
FROM `tb_topic` b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -9,11 +9,13 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd_mysqlconnector;Charset=utf8;SslMode=none;Max pool size=10")
|
||||
//.UseConnectionFactory(FreeSql.DataType.MySql, () => new MySql.Data.MySqlClient.MySqlConnection("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd_mysqlconnector;Charset=utf8;SslMode=none;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseMonitorCommand(
|
||||
cmd =>
|
||||
{
|
||||
cmd.CommandTimeout = 200000;
|
||||
Trace.WriteLine(cmd.CommandText);
|
||||
}, //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) =>
|
||||
|
@ -758,12 +758,16 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT sum(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -772,12 +776,16 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT min(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -786,12 +794,16 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT max(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -800,15 +812,29 @@ namespace FreeSql.Tests.Odbc.Dameng
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT avg(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME""
|
||||
FROM ""TB_TOPIC22"" a
|
||||
WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
FROM ""TB_TOPIC22"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -725,15 +725,18 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
[Fact]
|
||||
public void Sum()
|
||||
{
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 sum(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -742,12 +745,15 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 min(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -756,29 +762,45 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 max(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void Avg()
|
||||
{
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 avg(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime]
|
||||
FROM [tb_topic22] a
|
||||
WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
FROM [tb_topic22] b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -843,12 +843,16 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT sum(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -857,12 +861,16 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT min(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -871,12 +879,16 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT max(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -885,15 +897,29 @@ namespace FreeSql.Tests.Odbc.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT avg(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime`
|
||||
FROM `tb_topic` a
|
||||
WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
||||
FROM `tb_topic` b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -758,12 +758,16 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT sum(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -772,12 +776,16 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT min(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -786,12 +794,16 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT max(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -800,15 +812,29 @@ namespace FreeSql.Tests.Odbc.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT avg(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME""
|
||||
FROM ""TB_TOPIC22"" a
|
||||
WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
FROM ""TB_TOPIC22"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -815,12 +815,16 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT sum(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -829,12 +833,16 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT min(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -843,12 +851,16 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT max(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -857,15 +869,29 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT avg(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
||||
FROM ""tb_topic"" a
|
||||
WHERE ((((a.""id"")::varchar) in (SELECT b.""title""
|
||||
FROM ""tb_topic"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -706,15 +706,18 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
[Fact]
|
||||
public void Sum()
|
||||
{
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 sum(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -723,12 +726,15 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 min(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -737,29 +743,45 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 max(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void Avg()
|
||||
{
|
||||
var subquery = select.Where(a => a.Id < 100).ToSql(a => new
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 100).Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.Where(a => a.Id < 100).ToList(a => new
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 avg(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Where(b => b.Id < 100).Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime]
|
||||
FROM [tb_topic22] a
|
||||
WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
FROM [tb_topic22] b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ public class g
|
||||
{
|
||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcMySql, "Driver={MySQL ODBC 8.0 Unicode Driver};Server=127.0.0.1;Persist Security Info=False;Trusted_Connection=Yes;UID=root;PWD=root;DATABASE=cccddd_odbc;Charset=utf8;SslMode=none;Max pool size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcMySql, () => new System.Data.Odbc.OdbcConnection("Driver={MySQL ODBC 8.0 Unicode Driver};Server=127.0.0.1;Persist Security Info=False;Trusted_Connection=Yes;UID=root;PWD=root;DATABASE=cccddd_odbc;Charset=utf8;SslMode=none;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
@ -18,7 +19,9 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;Max pool size=3")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcSqlServer, () => new System.Data.Odbc.OdbcConnection("Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;"))
|
||||
//.UseConnectionString(FreeSql.DataType.OdbcSqlServer, "Driver={SQL Server};Server=192.168.164.129;Persist Security Info=False;Trusted_Connection=Yes;UID=sa;PWD=123456;DATABASE=ds_shop;")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcSqlServer, () => new System.Data.Odbc.OdbcConnection("Driver={SQL Server};Server=192.168.164.129;Persist Security Info=False;Trusted_Connection=Yes;UID=sa;PWD=123456;DATABASE=ds_shop;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
@ -29,6 +32,7 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcOracle, "Driver={Oracle in XE};Server=//127.0.0.1:1521/XE;Persist Security Info=False;Trusted_Connection=Yes;UID=odbc1;PWD=123456")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcOracle, () => new System.Data.Odbc.OdbcConnection("Driver={Oracle in XE};Server=//127.0.0.1:1521/XE;Persist Security Info=False;Trusted_Connection=Yes;UID=odbc1;PWD=123456"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseSyncStructureToUpper(true)
|
||||
@ -44,6 +48,7 @@ public class g
|
||||
{
|
||||
return new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcPostgreSQL, "Driver={PostgreSQL Unicode(x64)};Server=192.168.164.10;Port=5432;UID=postgres;PWD=123456;Database=tedb_odbc;Pooling=true;Maximum Pool Size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcPostgreSQL, () => new System.Data.Odbc.OdbcConnection("Driver={PostgreSQL Unicode(x64)};Server=192.168.164.10;Port=5432;UID=postgres;PWD=123456;Database=tedb_odbc;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseSyncStructureToLower(true)
|
||||
.UseLazyLoading(true)
|
||||
@ -56,6 +61,7 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> odbcLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.Odbc, "Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;Max pool size=5")
|
||||
//.UseConnectionFactory(FreeSql.DataType.Odbc, () => new System.Data.Odbc.OdbcConnection("Driver={SQL Server};Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_odbc;Pooling=true;"))
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
@ -65,6 +71,7 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> damemgLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||
//.UseConnectionFactory(FreeSql.DataType.OdbcDameng, () => new System.Data.Odbc.OdbcConnection("Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseSyncStructureToUpper(true)
|
||||
|
@ -874,12 +874,16 @@ namespace FreeSql.Tests.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT sum(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -888,12 +892,16 @@ namespace FreeSql.Tests.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT min(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -902,12 +910,16 @@ namespace FreeSql.Tests.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT max(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -916,15 +928,29 @@ namespace FreeSql.Tests.MySql
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5, (SELECT avg(b.`Id`)
|
||||
FROM `tb_topic` b
|
||||
limit 0,1) as6
|
||||
FROM `tb_topic` a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime`
|
||||
FROM `tb_topic` a
|
||||
WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
||||
FROM `tb_topic` b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -758,12 +758,16 @@ namespace FreeSql.Tests.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT sum(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -772,12 +776,16 @@ namespace FreeSql.Tests.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT min(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -786,12 +794,16 @@ namespace FreeSql.Tests.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT max(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -800,15 +812,29 @@ namespace FreeSql.Tests.Oracle
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, (SELECT avg(b.""ID"")
|
||||
FROM ""TB_TOPIC22"" b
|
||||
WHERE ROWNUM < 2) as6
|
||||
FROM ""TB_TOPIC22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME""
|
||||
FROM ""TB_TOPIC22"" a
|
||||
WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
FROM ""TB_TOPIC22"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -832,12 +832,16 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT sum(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = (long)select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -846,12 +850,16 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT min(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -860,12 +868,16 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT max(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -874,15 +886,29 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""id"" as1, a.""clicks"" as2, a.""typeguid"" as3, a.""title"" as4, a.""createtime"" as5, (SELECT avg(b.""id"")
|
||||
FROM ""tb_topic"" b
|
||||
limit 1) as6
|
||||
FROM ""tb_topic"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""id"", a.""clicks"", a.""typeguid"", a.""title"", a.""createtime""
|
||||
FROM ""tb_topic"" a
|
||||
WHERE ((((a.""id"")::varchar) in (SELECT b.""title""
|
||||
FROM ""tb_topic"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -754,12 +754,15 @@ namespace FreeSql.Tests.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 sum(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -768,12 +771,15 @@ namespace FreeSql.Tests.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 min(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -782,12 +788,15 @@ namespace FreeSql.Tests.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 max(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -796,15 +805,28 @@ namespace FreeSql.Tests.SqlServer
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, (SELECT TOP 1 avg(b.[Id])
|
||||
FROM [tb_topic22] b) as6
|
||||
FROM [tb_topic22] a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime]
|
||||
FROM [tb_topic22] a
|
||||
WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
FROM [tb_topic22] b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -711,12 +711,16 @@ namespace FreeSql.Tests.Sqlite
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""Id"" as1, a.""Clicks"" as2, a.""TypeGuid"" as3, a.""Title"" as4, a.""CreateTime"" as5, (SELECT sum(b.""Id"")
|
||||
FROM ""tb_topic22"" b
|
||||
limit 0,1) as6
|
||||
FROM ""tb_topic22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = (long)select.As("b").Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -725,12 +729,16 @@ namespace FreeSql.Tests.Sqlite
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""Id"" as1, a.""Clicks"" as2, a.""TypeGuid"" as3, a.""Title"" as4, a.""CreateTime"" as5, (SELECT min(b.""Id"")
|
||||
FROM ""tb_topic22"" b
|
||||
limit 0,1) as6
|
||||
FROM ""tb_topic22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Min(b => b.Id)
|
||||
count = select.As("b").Min(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -739,12 +747,16 @@ namespace FreeSql.Tests.Sqlite
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""Id"" as1, a.""Clicks"" as2, a.""TypeGuid"" as3, a.""Title"" as4, a.""CreateTime"" as5, (SELECT max(b.""Id"")
|
||||
FROM ""tb_topic22"" b
|
||||
limit 0,1) as6
|
||||
FROM ""tb_topic22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Max(b => b.Id)
|
||||
count = select.As("b").Max(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -753,15 +765,29 @@ namespace FreeSql.Tests.Sqlite
|
||||
var subquery = select.ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
Assert.Equal(@"SELECT a.""Id"" as1, a.""Clicks"" as2, a.""TypeGuid"" as3, a.""Title"" as4, a.""CreateTime"" as5, (SELECT avg(b.""Id"")
|
||||
FROM ""tb_topic22"" b
|
||||
limit 0,1) as6
|
||||
FROM ""tb_topic22"" a", subquery);
|
||||
var subqueryList = select.ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.As("b").Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void WhereIn()
|
||||
{
|
||||
var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql();
|
||||
Assert.Equal(@"SELECT a.""Id"", a.""Clicks"", a.""TypeGuid"", a.""Title"", a.""CreateTime""
|
||||
FROM ""tb_topic22"" a
|
||||
WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
||||
FROM ""tb_topic22"" b)))", subquery);
|
||||
var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList();
|
||||
}
|
||||
[Fact]
|
||||
public void As()
|
||||
{
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.MySql, () => new MySql.Data.MySqlClient.MySqlConnection("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseMonitorCommand(
|
||||
@ -25,6 +26,7 @@ public class g
|
||||
NpgsqlConnection.GlobalTypeMapper.UseLegacyPostgis();
|
||||
return new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.PostgreSQL, () => new Npgsql.NpgsqlConnection("Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseSyncStructureToLower(true)
|
||||
@ -39,7 +41,9 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
|
||||
//.UseConnectionFactory(FreeSql.DataType.SqlServer, () => new System.Data.SqlClient.SqlConnection("Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;"))
|
||||
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=192.168.164.129;uid=sa;pwd=123456;Initial Catalog=ds_shop;Pooling=true;Max Pool Size=3")
|
||||
//.UseConnectionFactory(FreeSql.DataType.SqlServer, () => new System.Data.SqlClient.SqlConnection("Data Source=192.168.164.129;uid=sa;pwd=123456;Initial Catalog=ds_shop;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseMonitorCommand(
|
||||
@ -52,6 +56,7 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.Oracle, () => new Oracle.ManagedDataAccess.Client.OracleConnection("user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;"))
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseLazyLoading(true)
|
||||
@ -67,6 +72,16 @@ public class g
|
||||
|
||||
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=2")
|
||||
//.UseConnectionFactory(FreeSql.DataType.Sqlite, () =>
|
||||
//{
|
||||
// var conn = new System.Data.SQLite.SQLiteConnection(@"Data Source=|DataDirectory|\document.db;Pooling=true;");
|
||||
// //conn.Open();
|
||||
// //var cmd = conn.CreateCommand();
|
||||
// //cmd.CommandText = $"attach database [xxxtb.db] as [xxxtb];\r\n";
|
||||
// //cmd.ExecuteNonQuery();
|
||||
// //cmd.Dispose();
|
||||
// return conn;
|
||||
//})
|
||||
.UseAutoSyncStructure(true)
|
||||
//.UseGenerateCommandParameterWithLambda(true)
|
||||
.UseLazyLoading(true)
|
||||
|
@ -68,7 +68,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "orm_vs_net40", "Examples\or
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Generator", "Extensions\FreeSql.Generator\FreeSql.Generator.csproj", "{6A3A4470-7DF7-411B-AAD7-755D7A9DB5A4}"
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "FreeSql.Tests.VB", "FreeSql.Tests.VB\FreeSql.Tests.VB.vbproj", "{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}"
|
||||
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "FreeSql.Tests.VB", "FreeSql.Tests.VB\FreeSql.Tests.VB.vbproj", "{A4FB811A-15EF-4E4C-AC15-826F9BB44E2D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -28,7 +28,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SafeObjectPool" Version="2.1.6" />
|
||||
<PackageReference Include="SafeObjectPool" Version="2.2.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -613,7 +613,7 @@
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseConnectionString(FreeSql.DataType,System.String,System.Type)">
|
||||
<summary>
|
||||
使用连接串
|
||||
使用连接串(推荐)
|
||||
</summary>
|
||||
<param name="dataType">数据库类型</param>
|
||||
<param name="connectionString">数据库连接串</param>
|
||||
@ -627,6 +627,15 @@
|
||||
<param name="slaveConnectionString">从数据库连接串</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseConnectionFactory(FreeSql.DataType,System.Func{System.Data.Common.DbConnection},System.Type)">
|
||||
<summary>
|
||||
使用自定义数据库连接对象(放弃内置对象连接池技术)
|
||||
</summary>
|
||||
<param name="dataType">数据库类型</param>
|
||||
<param name="connectionFactory">数据库连接对象创建器</param>
|
||||
<param name="providerType">提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseAutoSyncStructure(System.Boolean)">
|
||||
<summary>
|
||||
【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
|
||||
@ -2125,139 +2134,194 @@
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
|
||||
</summary>
|
||||
<param name="readerHander"></param>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteReaderAsync(dr => {}, "select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteArrayAsync("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataSetAsync("select * from user where age > @age; select 2", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataTableAsync("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteNonQueryAsync("delete from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteScalarAsync("select 1 from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.ParseExpression">
|
||||
<sum环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
|
||||
<summary>
|
||||
可自定义解析表达式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.ConfigEntity">
|
||||
<summary>
|
||||
自定义实体的配置,方便和多个 ORM 共同使用
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.ConfigEntityProperty">
|
||||
<summary>
|
||||
自定义实体的属性配置,方便和多个 ORM 共同使用
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.CurdBefore">
|
||||
<summary>
|
||||
增删查改,执行命令之前触发
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.CurdAfter">
|
||||
<summary>
|
||||
增删查改,执行命令完成后触发
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.SyncStructureBefore">
|
||||
<summary>
|
||||
CodeFirst迁移,执行之前触发
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.SyncStructureAfter">
|
||||
<summary>
|
||||
CodeFirst迁移,执行完成触发
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAop.AuditValue">
|
||||
<summary>
|
||||
Insert/Update自动值处理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.FreeParse">
|
||||
<summary>
|
||||
内置解析功能,可辅助您进行解析
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.Expression">
|
||||
<summary>
|
||||
需要您解析的表达式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.Result">
|
||||
<summary>
|
||||
解析后的内容
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.EntityType">
|
||||
<summary>
|
||||
实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.ModifyResult">
|
||||
<summary>
|
||||
实体配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.ModifyIndexResult">
|
||||
<summary>
|
||||
索引配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.EntityType">
|
||||
<summary>
|
||||
实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.Property">
|
||||
<summary>
|
||||
实体的属性
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.ModifyResult">
|
||||
<summary>
|
||||
实体的属性配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.Identifier">
|
||||
<summary>
|
||||
标识符,可将 CurdBefore 与 CurdAfter 进行匹配
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.CurdType">
|
||||
<summary>
|
||||
操作类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.EntityType">
|
||||
<summary>
|
||||
实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.Table">
|
||||
<summary>
|
||||
实体类型的元数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.Sql">
|
||||
<summary>
|
||||
执行的 SQL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.DbParms">
|
||||
<summary>
|
||||
参数化命令
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.Exception">
|
||||
<summary>
|
||||
发生的错误
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ExecuteResult">
|
||||
<summary>
|
||||
执行SQL命令,返回的结果
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ElapsedTicks">
|
||||
<summary>
|
||||
耗时(单位:Ticks)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ElapsedMilliseconds">
|
||||
<summary>
|
||||
耗时(单位:毫秒)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.Identifier">
|
||||
<summary>
|
||||
标识符,可将 SyncStructureBeforeEventArgs 与 SyncStructureAfterEventArgs 进行匹配
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.EntityTypes">
|
||||
<summary>
|
||||
实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
|
||||
<summary>
|
||||
执行的 SQL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Exception">
|
||||
<summary>
|
||||
发生的错误
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedTicks">
|
||||
<summary>
|
||||
耗时(单位:Ticks)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedMilliseconds">
|
||||
<summary>
|
||||
耗时(单位:毫秒)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.AuditValueType">
|
||||
<summary>
|
||||
类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Column">
|
||||
<summary>
|
||||
属性列的元数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Property">
|
||||
<summary>
|
||||
反射的属性信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Value">
|
||||
<summary>
|
||||
获取实体的属性值,也可以设置实体的属性新值
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsAutoSyncStructure">
|
||||
<summary>
|
||||
【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsSyncStructureToLower">
|
||||
@ -2848,160 +2912,3 @@
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
unc{``0,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<summary>
|
||||
使用 or 拼接两个 lambda 表达式
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="exp1"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<param name="exp2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``1(System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
将 lambda 表达式取反
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="exp"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeUtil.NewMongodbId">
|
||||
<summary>
|
||||
生成类似Mongodb的ObjectId有序、不重复Guid
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1">
|
||||
<summary>
|
||||
插入数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0)">
|
||||
<summary>
|
||||
插入数据,传入实体
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0[])">
|
||||
<summary>
|
||||
插入数据,传入实体数组
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.List{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1">
|
||||
<summary>
|
||||
修改数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
||||
<summary>
|
||||
修改数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1">
|
||||
<summary>
|
||||
查询数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
||||
<summary>
|
||||
查询数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1">
|
||||
<summary>
|
||||
删除数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
||||
<summary>
|
||||
删除数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步),60秒未执行完成(可能)被其他线程事务自动提交
|
||||
</summary>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.TimeSpan,System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)
|
||||
</summary>
|
||||
<param name="timeout">超时,未执行完成(可能)被其他线程事务自动提交</param>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Data.IsolationLevel,System.TimeSpan,System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)
|
||||
</summary>
|
||||
<param name="isolationLevel"></param>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
<param name="timeout">超时,未执行完成(可能)被其他线程事务自动提交</param>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Ado">
|
||||
<summary>
|
||||
数据库访问对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Aop">
|
||||
<summary>
|
||||
所有拦截方法都在这里
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.CodeFirst">
|
||||
<summary>
|
||||
CodeFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.DbFirst">
|
||||
<summary>
|
||||
DbFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.GlobalFilter">
|
||||
<summary>
|
||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -12,6 +12,7 @@ namespace FreeSql
|
||||
DataType _dataType;
|
||||
string _masterConnectionString;
|
||||
string[] _slaveConnectionString;
|
||||
Func<DbConnection> _connectionFactory;
|
||||
bool _isAutoSyncStructure = false;
|
||||
bool _isSyncStructureToLower = false;
|
||||
bool _isSyncStructureToUpper = false;
|
||||
@ -25,7 +26,7 @@ namespace FreeSql
|
||||
Type _providerType = null;
|
||||
|
||||
/// <summary>
|
||||
/// 使用连接串
|
||||
/// 使用连接串(推荐)
|
||||
/// </summary>
|
||||
/// <param name="dataType">数据库类型</param>
|
||||
/// <param name="connectionString">数据库连接串</param>
|
||||
@ -33,6 +34,7 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseConnectionString(DataType dataType, string connectionString, Type providerType = null)
|
||||
{
|
||||
if (_connectionFactory != null) throw new Exception("已经指定了 UseConnectionFactory,不能再指定 UseConnectionString");
|
||||
_dataType = dataType;
|
||||
_masterConnectionString = connectionString;
|
||||
_providerType = providerType;
|
||||
@ -45,10 +47,27 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseSlave(params string[] slaveConnectionString)
|
||||
{
|
||||
if (_connectionFactory != null) throw new Exception("已经指定了 UseConnectionFactory,不能再指定 UseSlave");
|
||||
_slaveConnectionString = slaveConnectionString;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用自定义数据库连接对象(放弃内置对象连接池技术)
|
||||
/// </summary>
|
||||
/// <param name="dataType">数据库类型</param>
|
||||
/// <param name="connectionFactory">数据库连接对象创建器</param>
|
||||
/// <param name="providerType">提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场</param>
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseConnectionFactory(DataType dataType, Func<DbConnection> connectionFactory, Type providerType = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_masterConnectionString) == false) throw new Exception("已经指定了 UseConnectionString,不能再指定 UseConnectionFactory");
|
||||
if (_slaveConnectionString?.Any() == true) throw new Exception("已经指定了 UseSlave,不能再指定 UseConnectionFactory");
|
||||
_dataType = dataType;
|
||||
_connectionFactory = connectionFactory;
|
||||
_providerType = providerType;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
|
||||
/// </summary>
|
||||
/// <param name="value">true:运行时检查自动同步结构, false:不同步结构</param>
|
||||
@ -149,7 +168,7 @@ namespace FreeSql
|
||||
public IFreeSql Build() => Build<IFreeSql>();
|
||||
public IFreeSql<TMark> Build<TMark>()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_masterConnectionString)) throw new Exception("参数 masterConnectionString 不可为空,请检查 UseConnectionString");
|
||||
if (string.IsNullOrEmpty(_masterConnectionString) && _connectionFactory == null) throw new Exception("参数 masterConnectionString 不可为空,请检查 UseConnectionString");
|
||||
IFreeSql<TMark> ret = null;
|
||||
var type = _providerType;
|
||||
if (type?.IsGenericType == true) type = type.MakeGenericType(typeof(TMark));
|
||||
@ -208,7 +227,7 @@ namespace FreeSql
|
||||
default: throw new Exception("未指定 UseConnectionString");
|
||||
}
|
||||
}
|
||||
ret = Activator.CreateInstance(type, new object[] { _masterConnectionString, _slaveConnectionString }) as IFreeSql<TMark>;
|
||||
ret = Activator.CreateInstance(type, new object[] { _masterConnectionString, _slaveConnectionString, _connectionFactory }) as IFreeSql<TMark>;
|
||||
if (ret != null)
|
||||
{
|
||||
ret.CodeFirst.IsAutoSyncStructure = _isAutoSyncStructure;
|
||||
|
@ -14,11 +14,11 @@ namespace FreeSql
|
||||
/// <summary>
|
||||
/// 主库连接池
|
||||
/// </summary>
|
||||
ObjectPool<DbConnection> MasterPool { get; }
|
||||
IObjectPool<DbConnection> MasterPool { get; }
|
||||
/// <summary>
|
||||
/// 从库连接池
|
||||
/// </summary>
|
||||
List<ObjectPool<DbConnection>> SlavePools { get; }
|
||||
List<IObjectPool<DbConnection>> SlavePools { get; }
|
||||
/// <summary>
|
||||
/// 监视数据库命令对象(执行前,调试)
|
||||
/// </summary>
|
||||
|
@ -660,6 +660,7 @@ namespace FreeSql.Internal
|
||||
case "Min":
|
||||
case "Max":
|
||||
case "Avg":
|
||||
case "ToList": //where in
|
||||
case "First":
|
||||
var anyArgs = exp3.Arguments;
|
||||
var exp3Stack = new Stack<Expression>();
|
||||
@ -732,6 +733,7 @@ namespace FreeSql.Internal
|
||||
if (fsql == null) fsql = Expression.Lambda(exp3tmp).Compile().DynamicInvoke();
|
||||
fsqlType = fsql?.GetType();
|
||||
if (fsqlType == null) break;
|
||||
if (exp3.Method.Name != "ToList")
|
||||
fsqlType.GetField("_limit", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(fsql, 1);
|
||||
fsqltables = fsqlType.GetField("_tables", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(fsql) as List<SelectTableInfo>;
|
||||
//fsqltables[0].Alias = $"{tsc._tables[0].Alias}_{fsqltables[0].Alias}";
|
||||
@ -915,6 +917,7 @@ namespace FreeSql.Internal
|
||||
if (string.IsNullOrEmpty(sqlSum) == false)
|
||||
return $"({sqlSum.Replace("\r\n", "\r\n\t")})";
|
||||
break;
|
||||
case "ToList":
|
||||
case "First":
|
||||
var tscClone2 = tsc.CloneDisableDiyParse();
|
||||
tscClone2.isDisableDiyParse = false;
|
||||
|
@ -14,7 +14,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public abstract partial class AdoProvider : IAdo, IDisposable
|
||||
{
|
||||
|
||||
protected abstract void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex);
|
||||
protected abstract void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex);
|
||||
protected abstract DbCommand CreateCommand();
|
||||
protected abstract DbParameter[] GetDbParamtersByObject(string sql, object obj);
|
||||
public Action<DbCommand> AopCommandExecuting { get; set; }
|
||||
@ -22,8 +22,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
protected bool IsTracePerformance => AopCommandExecuted != null;
|
||||
|
||||
public ObjectPool<DbConnection> MasterPool { get; protected set; }
|
||||
public List<ObjectPool<DbConnection>> SlavePools { get; } = new List<ObjectPool<DbConnection>>();
|
||||
public IObjectPool<DbConnection> MasterPool { get; protected set; }
|
||||
public List<IObjectPool<DbConnection>> SlavePools { get; } = new List<IObjectPool<DbConnection>>();
|
||||
public DataType DataType { get; }
|
||||
protected CommonUtils _util { get; set; }
|
||||
protected int slaveUnavailables = 0;
|
||||
@ -35,7 +35,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
this.DataType = dataType;
|
||||
}
|
||||
|
||||
void LoggerException(ObjectPool<DbConnection> pool, (DbCommand cmd, bool isclose) pc, Exception e, DateTime dt, StringBuilder logtxt, bool isThrowException = true)
|
||||
void LoggerException(IObjectPool<DbConnection> pool, (DbCommand cmd, bool isclose) pc, Exception e, DateTime dt, StringBuilder logtxt, bool isThrowException = true)
|
||||
{
|
||||
var cmd = pc.cmd;
|
||||
if (pc.isclose) pc.cmd.Connection.Close();
|
||||
@ -76,7 +76,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
AopCommandExecuted?.Invoke(cmd, log.ToString());
|
||||
|
||||
cmd.Parameters.Clear();
|
||||
if (isThrowException) throw e;
|
||||
if (isThrowException)
|
||||
{
|
||||
cmd.Dispose();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
internal Dictionary<string, PropertyInfo> GetQueryTypeProperties(Type type)
|
||||
@ -515,7 +519,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
//查从库
|
||||
this.SlavePools : (
|
||||
//查主库
|
||||
slaveUnavailables == this.SlavePools.Count ? new List<ObjectPool<DbConnection>>() :
|
||||
slaveUnavailables == this.SlavePools.Count ? new List<IObjectPool<DbConnection>>() :
|
||||
//查从库可用
|
||||
this.SlavePools.Where(sp => sp.IsAvailable).ToList());
|
||||
if (availables.Any())
|
||||
@ -556,6 +560,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(pool, pc, new Exception($"连接失败,准备切换其他可用服务器"), dt, logtxt, false);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
ExecuteReaderMultiple(multipleResult, connection, transaction, readerHander, cmdType, cmdText, cmdParms);
|
||||
return;
|
||||
}
|
||||
@ -618,6 +623,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(pool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
}
|
||||
public object[][] ExecuteArray(string cmdText, object parms = null) => ExecuteArray(null, null, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
public object[][] ExecuteArray(DbTransaction transaction, string cmdText, object parms = null) => ExecuteArray(null, transaction, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
@ -708,6 +714,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(this.MasterPool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
return val;
|
||||
}
|
||||
public object ExecuteScalar(string cmdText, object parms = null) => ExecuteScalar(null, null, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
@ -743,6 +750,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(this.MasterPool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
//查从库
|
||||
this.SlavePools : (
|
||||
//查主库
|
||||
slaveUnavailables == this.SlavePools.Count ? new List<ObjectPool<DbConnection>>() :
|
||||
slaveUnavailables == this.SlavePools.Count ? new List<IObjectPool<DbConnection>>() :
|
||||
//查从库可用
|
||||
this.SlavePools.Where(sp => sp.IsAvailable).ToList());
|
||||
if (availables.Any())
|
||||
@ -489,6 +489,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(pool, pc, new Exception($"连接失败,准备切换其他可用服务器"), dt, logtxt, false);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
await ExecuteReaderMultipleAsync(multipleResult, connection, transaction, readerHander, cmdType, cmdText, cmdParms);
|
||||
return;
|
||||
}
|
||||
@ -551,6 +552,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(pool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
}
|
||||
public Task<object[][]> ExecuteArrayAsync(string cmdText, object parms = null) => ExecuteArrayAsync(null, null, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
public Task<object[][]> ExecuteArrayAsync(DbTransaction transaction, string cmdText, object parms = null) => ExecuteArrayAsync(null, transaction, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
@ -642,6 +644,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(this.MasterPool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
return val;
|
||||
}
|
||||
public Task<object> ExecuteScalarAsync(string cmdText, object parms = null) => ExecuteScalarAsync(null, null, CommandType.Text, cmdText, GetDbParamtersByObject(cmdText, parms));
|
||||
@ -677,6 +680,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
LoggerException(this.MasterPool, pc, ex, dt, logtxt);
|
||||
pc.cmd.Parameters.Clear();
|
||||
pc.cmd.Dispose();
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
catch { }
|
||||
|
||||
ObjectPool<DbConnection>[] pools = null;
|
||||
IObjectPool<DbConnection>[] pools = null;
|
||||
for (var a = 0; a < 10; a++)
|
||||
{
|
||||
try
|
||||
|
134
FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs
Normal file
134
FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
public class DbConnectionPool : IObjectPool<DbConnection>
|
||||
{
|
||||
internal DataType _dataType;
|
||||
internal Func<DbConnection> _connectionFactory;
|
||||
int _id;
|
||||
public DbConnectionPool(DataType dataType, Func<DbConnection> connectionFactory)
|
||||
{
|
||||
_dataType = dataType;
|
||||
_connectionFactory = connectionFactory;
|
||||
Policy = new DbConnectionPoolPolicy(this);
|
||||
}
|
||||
|
||||
public IPolicy<DbConnection> Policy { get; }
|
||||
|
||||
public bool IsAvailable => true;
|
||||
public Exception UnavailableException => null;
|
||||
public DateTime? UnavailableTime => null;
|
||||
public string Statistics => "throw new NotImplementedException()";
|
||||
public string StatisticsFullily => "throw new NotImplementedException()";
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public Object<DbConnection> Get(TimeSpan? timeout = null)
|
||||
{
|
||||
var conn = _connectionFactory();
|
||||
if (conn.State != ConnectionState.Open)
|
||||
conn.Open();
|
||||
return Object<DbConnection>.InitWith(this, Interlocked.Increment(ref _id), conn);
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task<Object<DbConnection>> GetAsync()
|
||||
{
|
||||
var conn = _connectionFactory();
|
||||
if (conn.State != ConnectionState.Open)
|
||||
await conn.OpenAsync();
|
||||
return Object<DbConnection>.InitWith(this, Interlocked.Increment(ref _id), conn);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Return(Object<DbConnection> obj, bool isReset = false)
|
||||
{
|
||||
if (obj == null) return;
|
||||
Policy.OnDestroy(obj.Value);
|
||||
}
|
||||
|
||||
public bool SetUnavailable(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal class DbConnectionPoolPolicy : IPolicy<DbConnection>
|
||||
{
|
||||
DbConnectionPool Pool;
|
||||
public DbConnectionPoolPolicy(DbConnectionPool pool)
|
||||
{
|
||||
this.Pool = pool;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = typeof(DbConnectionPoolPolicy).GetType().FullName;
|
||||
public int PoolSize { get; set; } = 1000;
|
||||
public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(50);
|
||||
public int AsyncGetCapacity { get; set; } = 10000;
|
||||
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||
public int CheckAvailableInterval { get; set; } = 5;
|
||||
|
||||
public DbConnection OnCreate()
|
||||
{
|
||||
var conn = Pool._connectionFactory();
|
||||
if (conn.State != ConnectionState.Open)
|
||||
conn.Open();
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void OnDestroy(DbConnection obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj.State != ConnectionState.Closed)
|
||||
obj.Close();
|
||||
//obj.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGet(Object<DbConnection> obj)
|
||||
{
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
public Task OnGetAsync(Object<DbConnection> obj)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void OnGetTimeout()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnReturn(Object<DbConnection> obj)
|
||||
{
|
||||
}
|
||||
|
||||
public bool OnCheckAvailable(Object<DbConnection> obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnAvailable()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUnavailable()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -14,9 +14,14 @@ namespace FreeSql.MySql
|
||||
{
|
||||
|
||||
public MySqlAdo() : base(DataType.MySql) { }
|
||||
public MySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.MySql)
|
||||
public MySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.MySql)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.MySql, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new MySqlConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -59,9 +64,11 @@ namespace FreeSql.MySql
|
||||
return new MySqlCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as MySqlConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as MySqlConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -55,12 +55,12 @@ namespace FreeSql.MySql
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public MySqlProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public MySqlProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new MySqlUtils(this);
|
||||
this.InternalCommonExpression = new MySqlExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new MySqlAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new MySqlAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new MySqlDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -12,10 +12,15 @@ namespace FreeSql.Odbc.Dameng
|
||||
{
|
||||
class OdbcDamengAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcDamengAdo() : base(DataType.Oracle) { }
|
||||
public OdbcDamengAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Oracle)
|
||||
public OdbcDamengAdo() : base(DataType.OdbcDameng) { }
|
||||
public OdbcDamengAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcDameng)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcDameng, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcDamengConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -57,9 +62,11 @@ namespace FreeSql.Odbc.Dameng
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcDamengConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcDamengConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -21,9 +21,7 @@ namespace FreeSql.Odbc.Dameng
|
||||
|
||||
public OdbcDamengConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
this.UserId = userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
this.UserId = OdbcDamengConnectionPool.GetUserId(connectionString);
|
||||
|
||||
var policy = new OdbcOracleConnectionPoolPolicy
|
||||
{
|
||||
@ -37,6 +35,13 @@ namespace FreeSql.Odbc.Dameng
|
||||
this.unavailableHandler = unavailableHandler;
|
||||
}
|
||||
|
||||
public static string GetUserId(string connectionString)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
return userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
}
|
||||
|
||||
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||
{
|
||||
if (exception != null && exception is OdbcException)
|
||||
|
@ -77,7 +77,12 @@ namespace FreeSql.Odbc.Dameng
|
||||
|
||||
protected override string GetComparisonDDLStatements(params (Type entityType, string tableName)[] objects)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool).UserId;
|
||||
var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OdbcDamengConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
var seqcols = new List<(ColumnInfo, string[], bool)>(); //序列:列,表,自增
|
||||
var seqnameDel = new List<string>(); //要删除的序列+触发器
|
||||
|
||||
|
@ -28,12 +28,12 @@ namespace FreeSql.Odbc.Dameng
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcDamengProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcDamengProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcDamengUtils(this);
|
||||
this.InternalCommonExpression = new OdbcDamengExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcDamengAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcDamengAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcDamengDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -13,9 +13,14 @@ namespace FreeSql.Odbc.Default
|
||||
class OdbcAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcAdo() : base(DataType.Odbc) { }
|
||||
public OdbcAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Odbc)
|
||||
public OdbcAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.Odbc)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Odbc, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -60,9 +65,11 @@ namespace FreeSql.Odbc.Default
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
@ -37,12 +38,12 @@ namespace FreeSql.Odbc.Default
|
||||
/// <param name="masterConnectionString"></param>
|
||||
/// <param name="slaveConnectionString"></param>
|
||||
/// <param name="adapter">适配器</param>
|
||||
public OdbcProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcUtils(this);
|
||||
this.InternalCommonExpression = new OdbcExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.CodeFirst = new OdbcCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -14,9 +14,14 @@ namespace FreeSql.Odbc.GBase
|
||||
class OdbcGBaseAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcGBaseAdo() : base(DataType.PostgreSQL) { }
|
||||
public OdbcGBaseAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.PostgreSQL)
|
||||
public OdbcGBaseAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.PostgreSQL)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.PostgreSQL, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcGBaseConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -58,9 +63,11 @@ namespace FreeSql.Odbc.GBase
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcGBaseConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcGBaseConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -3,6 +3,7 @@ using FreeSql.Internal.CommonProvider;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Odbc.GBase
|
||||
@ -31,12 +32,12 @@ namespace FreeSql.Odbc.GBase
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcGBaseProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcGBaseProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcGBaseUtils(this);
|
||||
this.InternalCommonExpression = new OdbcGBaseExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcGBaseAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcGBaseAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcGBaseDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -13,10 +13,15 @@ namespace FreeSql.Odbc.MySql
|
||||
class OdbcMySqlAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
|
||||
public OdbcMySqlAdo() : base(DataType.MySql) { }
|
||||
public OdbcMySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.MySql)
|
||||
public OdbcMySqlAdo() : base(DataType.OdbcMySql) { }
|
||||
public OdbcMySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcMySql)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcMySql, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcMySqlConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -57,9 +62,11 @@ namespace FreeSql.Odbc.MySql
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcMySqlConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcMySqlConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -33,12 +33,12 @@ namespace FreeSql.Odbc.MySql
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcMySqlProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcMySqlProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcMySqlUtils(this);
|
||||
this.InternalCommonExpression = new OdbcMySqlExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcMySqlAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcMySqlAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcMySqlDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -12,10 +12,15 @@ namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
class OdbcOracleAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcOracleAdo() : base(DataType.Oracle) { }
|
||||
public OdbcOracleAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Oracle)
|
||||
public OdbcOracleAdo() : base(DataType.OdbcOracle) { }
|
||||
public OdbcOracleAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcOracle)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcOracle, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcOracleConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -57,9 +62,11 @@ namespace FreeSql.Odbc.Oracle
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcOracleConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcOracleConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -21,9 +21,7 @@ namespace FreeSql.Odbc.Oracle
|
||||
|
||||
public OdbcOracleConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
this.UserId = userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
this.UserId = OdbcOracleConnectionPool.GetUserId(connectionString);
|
||||
|
||||
var policy = new OdbcOracleConnectionPoolPolicy
|
||||
{
|
||||
@ -37,6 +35,13 @@ namespace FreeSql.Odbc.Oracle
|
||||
this.unavailableHandler = unavailableHandler;
|
||||
}
|
||||
|
||||
public static string GetUserId(string connectionString)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
return userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
}
|
||||
|
||||
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||
{
|
||||
if (exception != null && exception is OdbcException)
|
||||
|
@ -77,7 +77,12 @@ namespace FreeSql.Odbc.Oracle
|
||||
|
||||
protected override string GetComparisonDDLStatements(params (Type entityType, string tableName)[] objects)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OdbcOracleConnectionPool).UserId;
|
||||
var userId = (_orm.Ado.MasterPool as OdbcOracleConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OdbcOracleConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
var seqcols = new List<(ColumnInfo, string[], bool)>(); //序列:列,表,自增
|
||||
var seqnameDel = new List<string>(); //要删除的序列+触发器
|
||||
|
||||
|
@ -28,12 +28,12 @@ namespace FreeSql.Odbc.Oracle
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcOracleProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcOracleProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcOracleUtils(this);
|
||||
this.InternalCommonExpression = new OdbcOracleExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcOracleAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcOracleAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcOracleDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -13,10 +13,15 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
{
|
||||
class OdbcPostgreSQLAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcPostgreSQLAdo() : base(DataType.PostgreSQL) { }
|
||||
public OdbcPostgreSQLAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.PostgreSQL)
|
||||
public OdbcPostgreSQLAdo() : base(DataType.OdbcPostgreSQL) { }
|
||||
public OdbcPostgreSQLAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcPostgreSQL)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcPostgreSQL, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcPostgreSQLConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -58,9 +63,11 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcPostgreSQLConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcPostgreSQLConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -3,6 +3,7 @@ using FreeSql.Internal.CommonProvider;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Odbc.PostgreSQL
|
||||
@ -31,12 +32,12 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcPostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcPostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcPostgreSQLUtils(this);
|
||||
this.InternalCommonExpression = new OdbcPostgreSQLExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcPostgreSQLAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcPostgreSQLAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcPostgreSQLDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -13,10 +13,15 @@ namespace FreeSql.Odbc.SqlServer
|
||||
{
|
||||
class OdbcSqlServerAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OdbcSqlServerAdo() : base(DataType.SqlServer) { }
|
||||
public OdbcSqlServerAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.SqlServer)
|
||||
public OdbcSqlServerAdo() : base(DataType.OdbcSqlServer) { }
|
||||
public OdbcSqlServerAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcSqlServer)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcSqlServer, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OdbcSqlServerConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -73,9 +78,11 @@ namespace FreeSql.Odbc.SqlServer
|
||||
return new OdbcCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OdbcSqlServerConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OdbcSqlServerConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -3,6 +3,7 @@ using FreeSql.Internal.CommonProvider;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Odbc.SqlServer
|
||||
@ -27,12 +28,12 @@ namespace FreeSql.Odbc.SqlServer
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OdbcSqlServerProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OdbcSqlServerProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OdbcSqlServerUtils(this);
|
||||
this.InternalCommonExpression = new OdbcSqlServerExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OdbcSqlServerAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OdbcSqlServerAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OdbcSqlServerDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -13,9 +13,14 @@ namespace FreeSql.Oracle
|
||||
class OracleAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public OracleAdo() : base(DataType.Oracle) { }
|
||||
public OracleAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Oracle)
|
||||
public OracleAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.Oracle)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Oracle, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new OracleConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -59,9 +64,11 @@ namespace FreeSql.Oracle
|
||||
return cmd;
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as OracleConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as OracleConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -21,9 +21,7 @@ namespace FreeSql.Oracle
|
||||
|
||||
public OracleConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
this.UserId = userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
this.UserId = OracleConnectionPool.GetUserId(connectionString);
|
||||
|
||||
var policy = new OracleConnectionPoolPolicy
|
||||
{
|
||||
@ -37,6 +35,13 @@ namespace FreeSql.Oracle
|
||||
this.unavailableHandler = unavailableHandler;
|
||||
}
|
||||
|
||||
public static string GetUserId(string connectionString)
|
||||
{
|
||||
var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
|
||||
if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
|
||||
return userIdMatch.Groups[2].Value.Trim().ToUpper();
|
||||
}
|
||||
|
||||
public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
|
||||
{
|
||||
if (exception != null && exception is OracleException)
|
||||
|
@ -78,7 +78,12 @@ namespace FreeSql.Oracle
|
||||
|
||||
protected override string GetComparisonDDLStatements(params (Type entityType, string tableName)[] objects)
|
||||
{
|
||||
var userId = (_orm.Ado.MasterPool as OracleConnectionPool).UserId;
|
||||
var userId = (_orm.Ado.MasterPool as OracleConnectionPool)?.UserId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
userId = OracleConnectionPool.GetUserId(conn.Value.ConnectionString);
|
||||
}
|
||||
var seqcols = new List<(ColumnInfo, string[], bool)>(); //序列:列,表,自增
|
||||
var seqnameDel = new List<string>(); //要删除的序列+触发器
|
||||
|
||||
|
@ -29,12 +29,12 @@ namespace FreeSql.Oracle
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public OracleProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public OracleProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new OracleUtils(this);
|
||||
this.InternalCommonExpression = new OracleExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new OracleAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new OracleAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new OracleDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -15,9 +15,14 @@ namespace FreeSql.PostgreSQL
|
||||
class PostgreSQLAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public PostgreSQLAdo() : base(DataType.PostgreSQL) { }
|
||||
public PostgreSQLAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.PostgreSQL)
|
||||
public PostgreSQLAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.PostgreSQL)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.PostgreSQL, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new PostgreSQLConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -75,9 +80,11 @@ namespace FreeSql.PostgreSQL
|
||||
return new NpgsqlCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as PostgreSQLConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as PostgreSQLConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -82,12 +82,12 @@ namespace FreeSql.PostgreSQL
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public PostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public PostgreSQLProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new PostgreSQLUtils(this);
|
||||
this.InternalCommonExpression = new PostgreSQLExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new PostgreSQLAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new PostgreSQLAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new PostgreSQLDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -14,9 +14,14 @@ namespace FreeSql.SqlServer
|
||||
class SqlServerAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public SqlServerAdo() : base(DataType.SqlServer) { }
|
||||
public SqlServerAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.SqlServer)
|
||||
public SqlServerAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.SqlServer)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.SqlServer, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new SqlServerConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -73,9 +78,11 @@ namespace FreeSql.SqlServer
|
||||
return new SqlCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as SqlServerConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as SqlServerConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -4,6 +4,7 @@ using FreeSql.SqlServer.Curd;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.SqlServer
|
||||
@ -28,12 +29,12 @@ namespace FreeSql.SqlServer
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst { get; }
|
||||
public SqlServerProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public SqlServerProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new SqlServerUtils(this);
|
||||
this.InternalCommonExpression = new SqlServerExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new SqlServerAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new SqlServerAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.DbFirst = new SqlServerDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
@ -12,9 +12,14 @@ namespace FreeSql.Sqlite
|
||||
class SqliteAdo : FreeSql.Internal.CommonProvider.AdoProvider
|
||||
{
|
||||
public SqliteAdo() : base(DataType.Sqlite) { }
|
||||
public SqliteAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Sqlite)
|
||||
public SqliteAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.Sqlite)
|
||||
{
|
||||
base._util = util;
|
||||
if (connectionFactory != null)
|
||||
{
|
||||
MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.Sqlite, connectionFactory);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(masterConnectionString))
|
||||
MasterPool = new SqliteConnectionPool("主库", masterConnectionString, null, null);
|
||||
if (slaveConnectionStrings != null)
|
||||
@ -55,9 +60,11 @@ namespace FreeSql.Sqlite
|
||||
return AdonetPortable.GetSqliteCommand();
|
||||
}
|
||||
|
||||
protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
|
||||
{
|
||||
(pool as SqliteConnectionPool).Return(conn, ex);
|
||||
var rawPool = pool as SqliteConnectionPool;
|
||||
if (rawPool != null) rawPool.Return(conn, ex);
|
||||
else pool.Return(conn);
|
||||
}
|
||||
|
||||
protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
|
||||
|
@ -224,7 +224,10 @@ namespace FreeSql.Sqlite
|
||||
{
|
||||
try
|
||||
{
|
||||
PingCommand(that).ExecuteNonQuery();
|
||||
using (var cmd = PingCommand(that))
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@ -247,6 +250,7 @@ namespace FreeSql.Sqlite
|
||||
var cmd = that.CreateCommand();
|
||||
cmd.CommandText = sb.ToString();
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +260,10 @@ namespace FreeSql.Sqlite
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
using (var cmd = PingCommand(that))
|
||||
{
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@ -279,6 +286,7 @@ namespace FreeSql.Sqlite
|
||||
var cmd = that.CreateCommand();
|
||||
cmd.CommandText = sb.ToString();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -29,12 +29,12 @@ namespace FreeSql.Sqlite
|
||||
public IAop Aop { get; }
|
||||
public ICodeFirst CodeFirst { get; }
|
||||
public IDbFirst DbFirst => null;
|
||||
public SqliteProvider(string masterConnectionString, string[] slaveConnectionString)
|
||||
public SqliteProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
|
||||
{
|
||||
this.InternalCommonUtils = new SqliteUtils(this);
|
||||
this.InternalCommonExpression = new SqliteExpression(this.InternalCommonUtils);
|
||||
|
||||
this.Ado = new SqliteAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
|
||||
this.Ado = new SqliteAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
|
||||
this.Aop = new AopProvider();
|
||||
|
||||
this.CodeFirst = new SqliteCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
|
||||
|
Loading…
x
Reference in New Issue
Block a user