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裏維護!!!