Skip to content

Commit

Permalink
Merge pull request #1 from dotnetcore/master
Browse files Browse the repository at this point in the history
sync master
  • Loading branch information
EsonXie authored Dec 12, 2024
2 parents e882269 + 18b8613 commit 206762e
Show file tree
Hide file tree
Showing 98 changed files with 4,173 additions and 715 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!--
经常出于版本交叉问题,暂时关闭,在每个项目上设置版本号
<PropertyGroup>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
</PropertyGroup>
-->

Expand Down
168 changes: 95 additions & 73 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,39 +574,39 @@ static void Main(string[] args)
//.UseSlaveWeight(10, 1, 1, 5)


//.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
//.UseQuoteSqlName(false)

//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")

//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseAdoConnectionPool(false)
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseAdoConnectionPool(false)
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)

//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)

//.UseConnectionString(FreeSql.DataType.Dameng, "server=127.0.0.1;port=5236;user=2user;password=123456789;database=2user;poolsize=5;")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
//.UseConnectionString(FreeSql.DataType.Dameng, "server=127.0.0.1;port=5236;user=2user;password=123456789;database=2user;poolsize=5;")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)

//.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")
//.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")

//.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")
//.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")

//.UseConnectionString(FreeSql.DataType.OdbcPostgreSQL, "Driver={PostgreSQL Unicode(x64)};Server=127.0.0.1;Port=5432;UID=postgres;PWD=123456;Database=tedb_odbc;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
//.UseConnectionString(FreeSql.DataType.OdbcPostgreSQL, "Driver={PostgreSQL Unicode(x64)};Server=127.0.0.1;Port=5432;UID=postgres;PWD=123456;Database=tedb_odbc;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)

//.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")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
//.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")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)

//.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")
//.UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;")
//.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")
//.UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;")

//.UseConnectionString(DataType.ClickHouse, "DataCompress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Encrypt=False;Compressor=lz4;Host=192.168.0.121;Port=8125;Database=PersonnelLocation;Username=root;Password=123")
//.UseConnectionString(DataType.ClickHouse, "DataCompress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Encrypt=False;Compressor=lz4;Host=192.168.0.121;Port=8125;Database=PersonnelLocation;Username=root;Password=123")
//.UseConnectionFactory(DataType.ClickHouse, () => null)
.UseMonitorCommand(cmd =>
.UseMonitorCommand(cmd =>
{
Console.WriteLine(cmd.CommandText + "\r\n");
//cmd.CommandText = null; //不执行
Expand All @@ -619,6 +619,77 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

fsql.CodeFirst.SyncStructure<Account>();


var dbpars = new List<DbParameter>();

var a1id1 = Guid.NewGuid();
var a1id2 = Guid.NewGuid();
//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
var sql1a0 = fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id1)
.OrderBy(a => a.Id)

.UnionAll(
fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
.OrderByDescending(a => a.Id),

fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
.OrderByDescending(a => a.Id)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToList();
var sql1a1 = fsql.Select<User1>()
.Where(a => a.Id == a1id1)
.UnionAll(
fsql.Select<User1>()
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToList();
var sql1a2 = fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id1)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型

.UnionAll(
fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id2)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型
)

.Where(a => a.user.Id == a1id1 || a.user.Id == a1id2)
.ToList();

fsql.Aop.AuditValue += (_, e) =>
{

};

var tt1 = new ProjectItem { ID = 1, MaxQuantity = 0, Code = null, Name = null };
var tt2 = new ProjectItem { ID = 1, MaxQuantity = 100, Code = null, Name = null };
var repot2 = fsql.GetRepository<ProjectItem>();

repot2.Attach(tt1);
var nt1 = repot2.Update(tt2);

fsql.Delete<User1>().Where("1=1").ExecuteAffrows();
fsql.Insert(new List<User1>
{
new User1 { Nickname = "nickname11", Username = "username11", Description = "desc11" },
new User1 { Nickname = "n2", Username = "u2", Description = "d2" },
new User1 { Nickname = "n3", Username = "u3", Description = "d3" },
}).ExecuteAffrows();

var firebirdList01 = fsql.Select<User1>().ToList();

fsql.UseJsonMap();

fsql.Select<Table11>().Where(a => a.Options.Value1 == 100 && a.Options.Value2 == "xx").ToList();
Expand Down Expand Up @@ -711,17 +782,7 @@ static void Main(string[] args)

fsql.Select<User1>().Where(a => a.Id == new Guid("xxx")).ToList(a => new Guid("zzz"));

fsql.Aop.AuditValue += (_, e) =>
{

};

var tt1 = new ProjectItem { ID = 1, MaxQuantity = 0, Code = null, Name = null };
var tt2 = new ProjectItem { ID = 1, MaxQuantity = 100, Code = null, Name = null };
var repot2 = fsql.GetRepository<ProjectItem>();

repot2.Attach(tt1);
var nt1 = repot2.Update(tt2);


var fsql2 = fsql;
// 动态构建实体类型,树形结构,引用自身类型
Expand Down Expand Up @@ -1664,48 +1725,6 @@ static void Main(string[] args)
var sqlskdfj = fsql.Select<object>().AsType(typeof(BBB)).ToSql(a => new CCC());


var dbpars = new List<DbParameter>();

var a1id1 = Guid.NewGuid();
var a1id2 = Guid.NewGuid();
//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
var sql1a0 = fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id1)

.UnionAll(
fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2),

fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToSql();
var sql1a1 = fsql.Select<User1>()
.Where(a => a.Id == a1id1)
.UnionAll(
fsql.Select<User1>()
.Where(a => a.Id == a1id2)
)
.Where(a => a.Id == a1id1 || a.Id == a1id2)
.ToSql();
var sql1a2 = fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id1)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型

.UnionAll(
fsql.Select<User1, UserGroup>()
.InnerJoin((a, b) => a.GroupId == b.Id)
.Where((a, b) => a.Id == a1id2)
.WithTempQuery((a, b) => new { user = a, group = b }) //匿名类型
)

.Where(a => a.user.Id == a1id1 || a.user.Id == a1id2)
.ToSql();


var ddlsql01 = fsql.CodeFirst.GetComparisonDDLStatements<StringNulable>();
Expand Down Expand Up @@ -3293,6 +3312,9 @@ public partial class ProjectItem

}

/// <summary>
/// 账户
/// </summary>
[Table(Name = "t_account")]
public class Account
{
Expand Down
1 change: 0 additions & 1 deletion Examples/base_entity/base_entity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Npgsql.NetTopologySuite" Version="6.0.4" />
<PackageReference Include="MessagePack" Version="2.4.35" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.5" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Examples/base_entity/base_entity.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ async Task<int> DeleteWithinBoundaryAsync(IEnumerable<TEntity> entitys, List<obj
return affrows;
}

async public virtual Task SaveManyAsync(TEntity entity, string propertyName, CancellationToken cancellationToken = default)
{
var tracking = new AggregateRootTrackingChangeInfo();
var stateKey = Orm.GetEntityKeyString(EntityType, entity, false);
if (_states.TryGetValue(stateKey, out var state) == false) throw new Exception($"AggregateRootRepository 使用仓储对象查询后,才可以保存数据 {Orm.GetEntityString(EntityType, entity)}");
AggregateRootUtils.CompareEntityValue(_boundaryName, Orm, EntityType, state.Value, entity, propertyName, tracking);
await SaveTrackingChangeAsync(tracking, cancellationToken);
Attach(entity); //应该只存储 propertyName 内容
}

async Task<int> SaveTrackingChangeAsync(AggregateRootTrackingChangeInfo tracking, CancellationToken cancellationToken)
{
var affrows = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
13 changes: 13 additions & 0 deletions Extensions/FreeSql.Extensions.BaseEntity/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,18 @@ public virtual TEntity Save()
Repository.UnitOfWork = _resolveUow?.Invoke();
return Repository.InsertOrUpdate(this as TEntity);
}

/// <summary>
/// To completely save the navigation properties of the entity in the form of sub-tables. <br />
/// 【完整】保存导航属性,子表
/// </summary>
/// <param name="navigatePropertyName">Navigation property name</param>
public virtual void SaveMany(string navigatePropertyName)
{
if (Repository == null)
Repository = Orm.GetRepository<TEntity>();
Repository.UnitOfWork = _resolveUow?.Invoke();
Repository.SaveMany(this as TEntity, navigatePropertyName);
}
}
}
13 changes: 13 additions & 0 deletions Extensions/FreeSql.Extensions.BaseEntity/BaseEntityAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ public virtual Task<TEntity> SaveAsync()
Repository.UnitOfWork = _resolveUow?.Invoke();
return Repository.InsertOrUpdateAsync(this as TEntity);
}

/// <summary>
/// To completely save the navigation properties of the entity in the form of sub-tables. <br />
/// 【完整】保存导航属性,子表
/// </summary>
/// <param name="navigatePropertyName">Navigation property name</param>
public virtual Task SaveManyAsync(string navigatePropertyName)
{
if (Repository == null)
Repository = Orm.GetRepository<TEntity>();
Repository.UnitOfWork = _resolveUow?.Invoke();
return Repository.SaveManyAsync(this as TEntity, navigatePropertyName);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<LangVersion>latest</LangVersion>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>$(AssemblyName)</Title>
<IsPackable>true</IsPackable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.5.100-preview20241112</Version>
<Version>3.5.103-preview20241205</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ void LocalAdd(TableInfo table, T data, bool isCheck, ColumnInfo[] _tableReturnCo
case DataType.ShenTong:
case DataType.DuckDB:
case DataType.Firebird: //firebird 只支持单条插入 returning
case DataType.Xugu:
if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1)
{
var idtval = OrmInsert(table).AppendData(data).ExecuteIdentity();
Expand Down
Loading

0 comments on commit 206762e

Please sign in to comment.