Skip to content

Commit

Permalink
- 移除 Repository.DataFilter 功能通知;#1208
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jul 24, 2024
1 parent 04a538a commit 86669a2
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 247 deletions.
14 changes: 1 addition & 13 deletions Examples/repository_01/Controllers/SongController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace restful.Controllers
{

public class SongRepository : GuidRepository<Song>
public class SongRepository : BaseRepository<Song>
{
public SongRepository(IFreeSql fsql) : base(fsql)
{
Expand Down Expand Up @@ -43,18 +43,6 @@ IBaseRepository<TestSoftDelete> reposTest
Console.Write(reposTest.Select.ToSql());

_songRepository = repos4;
//test code
var curd1 = fsql.GetRepository<Song, int>();
var curd2 = fsql.GetRepository<Song, string>();
var curd3 = fsql.GetRepository<Song, Guid>();
var curd4 = fsql.GetGuidRepository<Song>();

Console.WriteLine(reposSong.Select.ToSql());

using (reposSong.DataFilter.DisableAll())
{
Console.WriteLine(reposSong.Select.ToSql());
}
}

[HttpGet]
Expand Down
13 changes: 0 additions & 13 deletions Extensions/FreeSql.Extensions.BaseEntity/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,5 @@ 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: 0 additions & 13 deletions Extensions/FreeSql.Extensions.BaseEntity/BaseEntityAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@ 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
}
}

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

2 changes: 1 addition & 1 deletion FreeSql.DbContext/FreeSql.DbContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="../readme.md" Pack="true" PackagePath="\"/>
<None Include="../readme.md" Pack="true" PackagePath="\" />
<None Include="../logo.png" Pack="true" PackagePath="\" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public RepositoryUnitOfWork(IFreeSql fsql) : base(fsql)
{
}

public IBaseRepository<TEntity> GetRepository<TEntity>() where TEntity : class
public IBaseRepository<TEntity> GetRepository<TEntity>() where TEntity : class => GetRepository<TEntity, int>();
public IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>() where TEntity : class
{
var repo = new DefaultRepository<TEntity, int>(_fsql);
var repo = new DefaultRepository<TEntity, TKey>(_fsql);
repo.UnitOfWork = this;
return repo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ partial class FreeSqlDbContextExtensions
/// <typeparam name="TEntity"></typeparam>
/// <param name="that"></param>
/// <returns></returns>
public static IBaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that) where TEntity : class
public static IBaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that) where TEntity : class => GetRepository<TEntity, int>(that);
public static IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this IFreeSql that) where TEntity : class
{
return new DefaultRepository<TEntity, int>(that);
return new DefaultRepository<TEntity, TKey>(that);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions FreeSql.Tests/FreeSql.Tests.DbContext/RepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public void AsType()
{
g.sqlite.Insert(new AddUpdateInfo()).ExecuteAffrows();

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

var item = new AddUpdateInfo();
Expand All @@ -627,7 +627,6 @@ public void AsType()
var item2 = repos.Find(item.Id) as AddUpdateInfo;
Assert.Equal(item.Clicks, item2.Clicks);

repos.DataFilter.Apply("xxx", a => (a as AddUpdateInfo).Clicks == 2);
Assert.Null(repos.Find(item.Id));
}

Expand Down
136 changes: 68 additions & 68 deletions FreeSql.Tests/FreeSql.Tests/Issues/1208.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ public void GlobalFilter01()
limit 0,1))
ORDER BY a.""Id"" DESC", sql);

using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
FROM ""issues1208_User"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser"" Mx_Mi
WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
FROM ""issues1208_DoorDevice"" x
WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"")
limit 0,1))
limit 0,1))
ORDER BY a.""Id"" DESC", sql);
}
// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
//FROM ""issues1208_User"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser"" Mx_Mi
// WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
// FROM ""issues1208_DoorDevice"" x
// WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"")
// limit 0,1))
// limit 0,1))
//ORDER BY a.""Id"" DESC", sql);
// }

sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
Expand Down Expand Up @@ -113,23 +113,23 @@ public void GlobalFilter01()
limit 0,1))
ORDER BY a.""Id"" DESC", sql);

using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
FROM ""issues1208_User"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDevice"" x
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser"" Mx_Ma
WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"")
limit 0,1)) AND (x.""Id"" = 100)
limit 0,1))
ORDER BY a.""Id"" DESC", sql);
}
// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
//FROM ""issues1208_User"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDevice"" x
// WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser"" Mx_Ma
// WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"")
// limit 0,1)) AND (x.""Id"" = 100)
// limit 0,1))
//ORDER BY a.""Id"" DESC", sql);
// }
}
}

Expand Down Expand Up @@ -231,23 +231,23 @@ public void GlobalFilter02()
limit 0,1)) AND (a.""SoftDeleted"" = 0)
ORDER BY a.""Id"" DESC", sql);

using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId"", a.""SoftDeleted""
FROM ""issues1208_User02"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser02"" Mx_Mi
WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
FROM ""issues1208_DoorDevice02"" x
WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"") AND (x.""SoftDeleted"" = 0)
limit 0,1)) AND (Mx_Mi.""SoftDeleted"" = 0)
limit 0,1)) AND (a.""SoftDeleted"" = 0)
ORDER BY a.""Id"" DESC", sql);
}
// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId"", a.""SoftDeleted""
//FROM ""issues1208_User02"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser02"" Mx_Mi
// WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
// FROM ""issues1208_DoorDevice02"" x
// WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"") AND (x.""SoftDeleted"" = 0)
// limit 0,1)) AND (Mx_Mi.""SoftDeleted"" = 0)
// limit 0,1)) AND (a.""SoftDeleted"" = 0)
//ORDER BY a.""Id"" DESC", sql);
// }

sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
Expand Down Expand Up @@ -279,23 +279,23 @@ public void GlobalFilter02()
limit 0,1)) AND (a.""SoftDeleted"" = 0)
ORDER BY a.""Id"" DESC", sql);

using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId"", a.""SoftDeleted""
FROM ""issues1208_User02"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDevice02"" x
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser02"" Mx_Ma
WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"") AND (Mx_Ma.""SoftDeleted"" = 0)
limit 0,1)) AND (x.""Id"" = 100) AND (x.""SoftDeleted"" = 0)
limit 0,1)) AND (a.""SoftDeleted"" = 0)
ORDER BY a.""Id"" DESC", sql);
}
// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId"", a.""SoftDeleted""
//FROM ""issues1208_User02"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDevice02"" x
// WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser02"" Mx_Ma
// WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"") AND (Mx_Ma.""SoftDeleted"" = 0)
// limit 0,1)) AND (x.""Id"" = 100) AND (x.""SoftDeleted"" = 0)
// limit 0,1)) AND (a.""SoftDeleted"" = 0)
//ORDER BY a.""Id"" DESC", sql);
// }
}
}

Expand Down
10 changes: 0 additions & 10 deletions FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,6 @@ public void Test02()
var gft2 = g.mysql.Select<gf_t2>().Where(a => a.id == Guid.NewGuid()).ToList();
var gft3 = g.mysql.Select<gf_t3>().Where(a => a.id == Guid.NewGuid()).ToList();

var repo1 = g.mysql.GetRepository<gf_t1, Guid>();
using (repo1.DataFilter.Disable("gft1", "gft2", "gft3"))
repo1.Get(Guid.NewGuid());
var repo2 = g.mysql.GetRepository<gf_t2, Guid>();
using (repo2.DataFilter.Disable("gft1", "gft2", "gft3"))
repo2.Get(Guid.NewGuid());
var repo3 = g.mysql.GetRepository<gf_t3, Guid>();
using (repo3.DataFilter.Disable("gft1", "gft2", "gft3"))
repo3.Get(Guid.NewGuid());

g.sqlserver.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
g.mysql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
g.pgsql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
Expand Down
Loading

0 comments on commit 86669a2

Please sign in to comment.