Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Includemany的softdelete问题 #1028

Closed
ymb27 opened this issue Feb 14, 2022 · 14 comments
Closed

Includemany的softdelete问题 #1028

ymb27 opened this issue Feb 14, 2022 · 14 comments

Comments

@ymb27
Copy link

ymb27 commented Feb 14, 2022

问题描述及重现步骤:

使用了includemany进行贪婪加载后全局设置的softdelete过滤器不起作用,代码如下。


var laneRepos = _unitOfWork.GetRepository<Lane>();
var lane = await laneRepos.Select.Where(a => a.Id == id).IncludeMany(a => a.Cards.Where(b => b.LaneId == a.Id)).ToOneAsync();
...

全局软删除过滤器配置如下。


services.AddFreeRepository(filter => 
                filter.Apply<ISoftDelete>("softdelete", a => a.IsDeleted == false),
                this.GetType().Assembly
);

查询结果如下。
image

数据库使用sql查询结果如下。
image

数据库的具体版本

mssql 2019 - 15.0.4198.2

安装的包

FreeSql.DbContext 2.6.100
FreeSql.Repository 2.6.100
FreeSql.Provider.SqlServer 2.6.100
FreeSql.Extensions.LazyLoading 2.6.100

.net framework/. net core? 及具体版本

.NET 5.0
@luoyunchong
Copy link
Collaborator

请换 全局过滤 器。https://github.com/dotnetcore/FreeSql/wiki/%e8%bf%87%e6%bb%a4%e5%99%a8
而不是你现在使用的仓储过滤器。

@ZevFung
Copy link

ZevFung commented May 18, 2022

同问

@2881099
Copy link
Collaborator

2881099 commented May 18, 2022

同问

请换 全局过滤 器。https://github.com/dotnetcore/FreeSql/wiki/%e8%bf%87%e6%bb%a4%e5%99%a8
而不是你现在使用的仓储过滤器。

@ZevFung
Copy link

ZevFung commented May 19, 2022

使用仓储过滤器

            services.AddFreeRepository(filter =>
            {
                filter.Apply<IEntitySoftDelete>("SoftDelete", a => a.IsDeleted == 0);
                filter.Apply<IEntityCompany<long>>("TenantQuery", a => a.CompanyId == 1);
            }, this.GetType().Assembly);
private readonly IUserRepository _userRepository;
public AuthService(
            IUserRepository userRepository
        )
        {
            _userRepository.DataFilter.Disable("TenantQuery");
        }

user = await _userRepository.GetAsync(1);

改使用全局过滤器

fsql.GlobalFilter.Apply<IEntitySoftDelete>("SoftDelete", a => a.IsDeleted == 0)
                .Apply<IEntityCompany<long>>("TenantQuery", a => a.CompanyId == 1);

不生效

user = await _userRepository.GetAsync(1);

改成以下生效

user = await _userRepository.Select.DisableGlobalFilter("TenantQuery").WhereDynamic(1).ToOneAsync();

很多地方用到仓储的方法,都得修改。请问有没有什么办法像下面配置就可以使用全局过滤器

_userRepository.DataFilter.Disable("TenantQuery");

@2881099
Copy link
Collaborator

2881099 commented May 19, 2022

这样才是正确用法:

using (_userRepository.DataFilter.Disable("TenantQuery"))
{
    var user = await _userRepository.GetAsync(1);
}

repo.DataFilter.Disable 可以禁用全局过滤器的,你使用的哪个版本?

@ZevFung
Copy link

ZevFung commented May 19, 2022

使用过没生效

using (_userRepository.DataFilter.Disable("TenantQuery"))
{
    var user = await _userRepository.GetAsync(1);
}

freesql 版本1.8.1

@2881099
Copy link
Collaborator

2881099 commented May 19, 2022

v2.3.100

  • 优化 Repository.DataFilter 可禁用 GlobalFilter;

@2881099
Copy link
Collaborator

2881099 commented May 19, 2022

升级注意事项:#563

@ZevFung
Copy link

ZevFung commented May 19, 2022

感谢,我试下

@ZevFung
Copy link

ZevFung commented May 19, 2022

下午好,freesql 版本升级到2.3.106了

Repository.DataFilter 无法禁用 GlobalFilter

using (_userRepository.DataFilter.Disable("TenantQuery"))
{
    var user = await _userRepository.GetAsync(1);
}

@ZevFung
Copy link

ZevFung commented May 20, 2022

v2.3.100
存在 GlobalFilter 在 Repository 失效的

升级到2.3.106
Repository.DataFilter 无法禁用 GlobalFilter

@2881099
Copy link
Collaborator

2881099 commented May 20, 2022

@ZevFung 这个确实无效,等会修复发布

@2881099
Copy link
Collaborator

2881099 commented May 20, 2022

v3.2.650-preview20220520 版本已发布,10分钟后更新

@ZevFung
Copy link

ZevFung commented May 20, 2022

感谢,测试过,已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants