Skip to content

Commit

Permalink
v3.5.100-preview20240725 #1830 #1861 #1208
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jul 24, 2024
1 parent 86669a2 commit d8965d5
Show file tree
Hide file tree
Showing 49 changed files with 223 additions and 174 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!--
经常出于版本交叉问题,暂时关闭,在每个项目上设置版本号
<PropertyGroup>
<Version>3.2.833</Version>
<Version>3.5.100-preview20240725</Version>
</PropertyGroup>
-->

Expand Down
3 changes: 1 addition & 2 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class EnterpriseInfo

public class SongRepository : BaseRepository<TUserImg, int>
{
public SongRepository(IFreeSql fsql) : base(fsql, null, null)
public SongRepository(IFreeSql fsql) : base(fsql)
{
//fsql.CodeFirst.Entity<TUserImg>(a =>
// {
Expand Down Expand Up @@ -706,7 +706,6 @@ static void Main(string[] args)
var testRepo = fsql2.GetRepository<object>();
testRepo.AsType(table.Type);
testRepo.Insert(area1);
testRepo.SaveMany(area1, "children");



Expand Down
7 changes: 1 addition & 6 deletions Examples/repository_01/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllersWithViews();
services.AddSingleton<IFreeSql>(Fsql);

services.AddFreeRepository(filter =>
{
filter
//.Apply<Song>("test", a => a.Title == DateTime.Now.ToString() + System.Threading.Thread.CurrentThread.ManagedThreadId)
.Apply<ISoftDelete>("softdelete", a => a.IsDeleted == false);
}, this.GetType().Assembly);
services.AddFreeRepository(this.GetType().Assembly);
}

public void Configure(IApplicationBuilder app)
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.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
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.2.833</Version>
<Version>3.5.100-preview20240725</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.2.833</Version>
<Version>3.5.100-preview20240725</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.2.833</Version>
<Version>3.5.100-preview20240725</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.2.833</Version>
<Version>3.5.100-preview20240725</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.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Extensions/FreeSql.Generator/FreeSql.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
<PackageTags>FreeSql DbFirst 实体生成器</PackageTags>
<Version>3.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion FreeSql.All/FreeSql.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion FreeSql.DbContext/FreeSql.DbContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IRepositoryUnitOfWork : IUnitOfWork
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
IBaseRepository<TEntity> GetRepository<TEntity>() where TEntity : class;
IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>() where TEntity : class;
}

class RepositoryUnitOfWork : UnitOfWork, IRepositoryUnitOfWork
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this I
/// </summary>
/// <param name="that"></param>
/// <returns></returns>
public static IUnitOfWork CreateUnitOfWork(this IFreeSql that)
public static IRepositoryUnitOfWork CreateUnitOfWork(this IFreeSql that)
{
return new UnitOfWork(that);
return new RepositoryUnitOfWork(that);
}
}
2 changes: 1 addition & 1 deletion FreeSql.Repository/FreeSql.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.833</Version>
<Version>3.5.100-preview20240725</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
66 changes: 5 additions & 61 deletions FreeSql.Tests/FreeSql.Tests.DbContext/RepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public async Task Updatemysql()
var item3 = new AddUpdateInfo();
g.mysql.Insert(item3).ExecuteAffrows();

var repos = g.mysql.GetGuidRepository<AddUpdateInfo>();
var repos = g.mysql.GetRepository<AddUpdateInfo, Guid>();
var items = repos.Select.WhereDynamic(new[] { item1, item2, item3 }).ToList();
items[0].Title = "88";
//items[1].Title = "88";
Expand All @@ -433,7 +433,7 @@ public async Task Updatemysql()
[Fact]
public void AddUpdate()
{
var repos = g.sqlite.GetGuidRepository<AddUpdateInfo>();
var repos = g.sqlite.GetRepository<AddUpdateInfo, Guid>();

var item = repos.Insert(new AddUpdateInfo());
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(item));
Expand Down Expand Up @@ -462,7 +462,7 @@ public void AddUpdate()
[Fact]
public void UpdateAttach()
{
var repos = g.sqlite.GetGuidRepository<AddUpdateInfo>();
var repos = g.sqlite.GetRepository<AddUpdateInfo, Guid>();

var item = new AddUpdateInfo { Id = Guid.NewGuid() };
repos.Attach(item);
Expand All @@ -485,7 +485,7 @@ public void UpdateAttach()
[Fact]
public void UpdateWhenNotExists()
{
var repos = g.sqlite.GetGuidRepository<AddUpdateInfo>();
var repos = g.sqlite.GetRepository<AddUpdateInfo, Guid>();

var item = new AddUpdateInfo { Id = Guid.NewGuid() };
item.Title = "xxx";
Expand All @@ -497,7 +497,7 @@ public void Update()
{
g.sqlite.Insert(new AddUpdateInfo()).ExecuteAffrows();

var repos = g.sqlite.GetGuidRepository<AddUpdateInfo>();
var repos = g.sqlite.GetRepository<AddUpdateInfo, Guid>();

var item = new AddUpdateInfo { Id = g.sqlite.Select<AddUpdateInfo>().First().Id };

Expand Down Expand Up @@ -674,7 +674,6 @@ public void EnableCascadeSave_OneToMany()
cts2[0].Goodss[0].Name += 123;
repo.Update(cts2[0]);
cts2[0].Goodss[0].Name += 333;
repo.SaveMany(cts2[0], "Goodss");
}
[Table(Name = "EAUNL_OTM_CT")]
class Cagetory
Expand Down Expand Up @@ -737,13 +736,11 @@ public void EnableCascadeSave_OneToMany_lazyloading()
cts2[0].Goodss[0].Name += 123;
repo.Update(cts2[0]);
cts2[0].Goodss[0].Name += 333;
repo.SaveMany(cts2[0], "Goodss");

cts2 = repo.Select.WhereDynamic(cts).ToList();
cts2[0].Goodss[0].Name += 123;
repo.Update(cts2[0]);
cts2[0].Goodss[0].Name += 333;
repo.SaveMany(cts2[0], "Goodss");
}
[Table(Name = "EAUNL_OTM_CTLD")]
public class CagetoryLD
Expand All @@ -762,58 +759,6 @@ public class GoodsLD
public string Name { get; set; }
}

[Fact]
public void SaveMany_OneToMany()
{
var repo = g.sqlite.GetRepository<Cagetory>();
repo.DbContextOptions.EnableCascadeSave = false; //关闭级联保存功能
var cts = new[] {
new Cagetory
{
Name = "分类1",
Goodss = new List<Goods>(new[]
{
new Goods { Name = "商品1" },
new Goods { Name = "商品2" },
new Goods { Name = "商品3" }
})
},
new Cagetory
{
Name = "分类2",
Goodss = new List<Goods>(new[]
{
new Goods { Name = "商品4" },
new Goods { Name = "商品5" }
})
}
};
repo.Insert(cts);
repo.SaveMany(cts[0], "Goodss"); //指定保存 Goodss 一对多属性
repo.SaveMany(cts[1], "Goodss"); //指定保存 Goodss 一对多属性
cts[0].Goodss.RemoveAt(1);
cts[1].Goodss.RemoveAt(1);
repo.SaveMany(cts[0], "Goodss"); //指定保存 Goodss 一对多属性
repo.SaveMany(cts[1], "Goodss"); //指定保存 Goodss 一对多属性

cts[0].Name = "分类11";
cts[0].Goodss.Clear();
cts[1].Name = "分类22";
cts[1].Goodss.Clear();
repo.Update(cts);
repo.SaveMany(cts[0], "Goodss"); //指定保存 Goodss 一对多属性
repo.SaveMany(cts[1], "Goodss"); //指定保存 Goodss 一对多属性
cts[0].Name = "分类111";
cts[0].Goodss.Clear();
cts[0].Goodss.Add(new Goods { Name = "商品33" });
cts[1].Name = "分类222";
cts[1].Goodss.Clear();
cts[1].Goodss.Add(new Goods { Name = "商品55" });
repo.Update(cts);
repo.SaveMany(cts[0], "Goodss"); //指定保存 Goodss 一对多属性
repo.SaveMany(cts[1], "Goodss"); //指定保存 Goodss 一对多属性
}

[Fact]
public void EnableCascadeSave_OneToMany_Parent()
{
Expand Down Expand Up @@ -905,7 +850,6 @@ public void EnableCascadeSave_ManyToMany()
repo.Insert(ss);

ss[0].Tags[0].TagName = "流行101";
repo.SaveMany(ss[0], "Tags"); //指定保存 Tags 多对多属性

ss[0].Name = "爱你一万年.mp5";
ss[0].Tags.Clear();
Expand Down
10 changes: 5 additions & 5 deletions FreeSql.Tests/FreeSql.Tests.DbContext/RepositoryTests02.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public void TestMethod1()

Console.WriteLine("仓储的过滤器禁止,但不成功.");
//仓储的过滤器禁止,但不成功.
using (resp.DataFilter.DisableAll())
{
//using (resp.DataFilter.DisableAll())
//{

long count2 = resp.Where(a => a.ID != null).Count();
// long count2 = resp.Where(a => a.ID != null).Count();

Assert.True(count2 == 4);
}
// Assert.True(count2 == 4);
//}

}
}
Expand Down
3 changes: 0 additions & 3 deletions FreeSql.Tests/FreeSql.Tests.DbContext/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ public void Include_ManyToMany()
new DEPARTMENTS { deptid = 2, deptcode = "02", deptname = "" },
new DEPARTMENTS { deptid = 3, deptcode = "03" , deptname = ""},
});
user.SaveMany("depts");

user.depts = new List<DEPARTMENTS>(
new[] {
new DEPARTMENTS { deptid = 1, deptcode = "01", deptname = "" },
new DEPARTMENTS { deptid = 2, deptcode = "02", deptname = "" },
new DEPARTMENTS { deptid = 4, deptcode = "04", deptname = "" },
});
user.SaveMany("depts");

user.depts = new List<DEPARTMENTS>(
new[] {
new DEPARTMENTS { deptid = 2, deptcode = "02", deptname = "" },
});
user.SaveMany("depts");

g.sqlite.CodeFirst.SyncStructure<Song_tag>();
g.sqlite.CodeFirst.SyncStructure<Tag>();
Expand Down
2 changes: 1 addition & 1 deletion FreeSql.Tests/FreeSql.Tests.Provider.Custom/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public void Test1()


g.mysql.SetDbContextOptions(opt => opt.EnableCascadeSave = true);
var trepo = g.mysql.GetGuidRepository<TaskBuild>();
var trepo = g.mysql.GetRepository<TaskBuild, Guid>();
trepo.Insert(new TaskBuild
{
TaskName = "tt11",
Expand Down
2 changes: 1 addition & 1 deletion FreeSql.Tests/FreeSql.Tests.Provider.Odbc/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public void Test1()


g.mysql.SetDbContextOptions(opt => opt.EnableCascadeSave = true);
var trepo = g.mysql.GetGuidRepository<TaskBuild>();
var trepo = g.mysql.GetRepository<TaskBuild, Guid>();
trepo.Insert(new TaskBuild
{
TaskName = "tt11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,10 @@ public void AsTable()
var listt = select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList();

var tenantId = 1;
var reposTopic = g.sqlite.GetGuidRepository<Topic>(null, oldname => $"{oldname}_{tenantId}");
var reposType = g.sqlite.GetGuidRepository<TestTypeInfo>(null, oldname => $"{oldname}_{tenantId}");
var reposTopic = g.sqlite.GetRepository<Topic, Guid>();
var reposType = g.sqlite.GetRepository<TestTypeInfo, Guid>();
reposTopic.AsTable(oldname => $"{oldname}_{tenantId}");
reposType.AsTable(oldname => $"{oldname}_{tenantId}");

//reposTopic.Delete(Guid.Empty);
//reposTopic.Find(Guid.Empty);
Expand Down
Loading

0 comments on commit d8965d5

Please sign in to comment.