tnblog
首页
视频
资源
登录

ABP 多租户数据共享

3893人阅读 2022/1/18 15:03 总访问:1091271 评论:0 收藏:0 手机
分类: ABP

转载于:https://www.cnblogs.com/Martincheng/p/10185430.html


ABP开启多租户,实体继承了IMayHaveTenant或者IMustHaveTenant各个租户数据就自动过滤。

我的需求是宿主(管理租户的,租户上一级),能查询全部数据。

查询ABP文档有一个禁用过滤器概念

注入IUnitOfWorkManager

禁用过滤方法

/* if (AbpSession.TenantId.ToString() == "1")//当前是租户xx查询全部数据
   {
                //禁用MustHaveTenant过滤,这里还可以传多个租户参数
          using (_IUnitOfWorkRepository.Current.DisableFilter(AbpDataFilters.MustHaveTenant))
       {
       //具体的业务逻辑
        }
       }
*/
if (AbpSession.MultiTenancySide.ToString() == "Host")//当前是宿主查询全部数据,其实就是在说明的情况下可以禁用MayHaveTenant过滤
            {
                using (_unitofwork.Current.DisableFilter(AbpDataFilters.MayHaveTenant))//禁用MayHaveTenant过滤
                {
                //using里面是具体的逻辑
                    query = _entityRepository.GetAll();

                    var count = await query.CountAsync();

                    var entityList = await query
                        .OrderBy(input.Sorting).AsNoTracking()
                        .PageBy(input)
                        .ToListAsync();

                    // var entityListDtos = ObjectMapper.Map<List<GatherListDto>>(entityList);
                    var entityListDtos = entityList.MapTo<List<GatherListDto>>();

                    return new PagedResultDto<GatherListDto>(count, entityListDtos);
                }

            }


评价
没有个性,不需要签名
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术