首页 > 其他分享 >abp-vnext-pro 实战(四,给客户表增加多租户)

abp-vnext-pro 实战(四,给客户表增加多租户)

时间:2023-08-05 11:55:05浏览次数:51  
标签:vnext filter domain 租户 pro abp int IsNullOrWhiteSpace

XXXHttpApiHostModule 里面默认启用多租户

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();

            。。。

            if (MultiTenancyConsts.IsEnabled)
            {
                app.UseMultiTenancy();
            }

 

增加多租户很简单,domain类里实现IMultiTenant接口就可以了

 Customer : FullAuditedAggregateRoot<Guid>, IMultiTenant

 在浏览器标头可以看到

 

        public async Task<List<Customer>> GetListAsync(int maxResultCount = 10, int skipCount = 0,
            string filter=null)
        {


        return await (await GetDbSetAsync())
                .WhereIf(!filter.IsNullOrWhiteSpace(),
                x => x.Name.Contains(filter))
                .OrderByDescending(e => e.CreationTime)
                .PageBy(skipCount, maxResultCount)
                .ToListAsync();
        }

不能这样写

        //unable to cast object of type
        //'microsoft.entityframeworkcore.query.internal.entityqueryable`1[fox.erp.domain.customer]'
        //to type 'microsoft.entityframeworkcore.dbset`
.WhereIf(!filter.IsNullOrWhiteSpace(),
                (Customer x) => x.Name.Contains(filter))

 

不要在Domain 项目里的CustomerManager.cs里的UpdateAsync 加上TenantId字段,这个由系统维护!!!

也不需要在DTO里维护!!!

 

标签:vnext,filter,domain,租户,pro,abp,int,IsNullOrWhiteSpace
From: https://www.cnblogs.com/zitjubiz/p/17604125.html

相关文章