Browse Source

fix(saas): fixed failure to query tenant list when not associated with edition

pull/765/head
cKey 3 years ago
parent
commit
ee3a5bd5de
  1. 1
      aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs
  2. 11
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/AbpNotificationsEntityFrameworkCoreModule.cs
  3. 4
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionGroupRecordRepository.cs
  4. 4
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionRecordRepository.cs
  5. 11
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/INotificationsDefinitionDbContext.cs
  6. 19
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs
  7. 23
      aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDefinitionDbContext.cs
  8. 36
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs
  9. 2
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs

1
aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs

@ -20,6 +20,7 @@ public class RealtimeMessageMigrationsDbContext : AbpDbContext<RealtimeMessageMi
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigureNotifications();
modelBuilder.ConfigureNotificationsDefinition();
modelBuilder.ConfigureMessageService();
}
}

11
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/AbpNotificationsEntityFrameworkCoreModule.cs

@ -1,7 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Notifications.EntityFrameworkCore;
@ -20,11 +19,17 @@ public class AbpNotificationsEntityFrameworkCoreModule : AbpModule
options.AddDefaultRepositories<INotificationsDbContext>();
options.AddRepository<Notification, EfCoreNotificationRepository>();
options.AddRepository<NotificationDefinitionRecord, EfCoreNotificationDefinitionRecordRepository>();
options.AddRepository<NotificationDefinitionGroupRecord, EfCoreNotificationDefinitionGroupRecordRepository>();
options.AddRepository<UserNotification, EfCoreUserNotificationRepository>();
options.AddRepository<UserSubscribe, EfCoreUserSubscribeRepository>();
});
context.Services.AddAbpDbContext<NotificationsDefinitionDbContext>(options =>
{
options.AddDefaultRepositories<INotificationsDefinitionDbContext>();
options.AddRepository<NotificationDefinitionRecord, EfCoreNotificationDefinitionRecordRepository>();
options.AddRepository<NotificationDefinitionGroupRecord, EfCoreNotificationDefinitionGroupRecordRepository>();
});
}
}

4
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionGroupRecordRepository.cs

@ -6,12 +6,12 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.Notifications.EntityFrameworkCore;
public class EfCoreNotificationDefinitionGroupRecordRepository :
EfCoreRepository<INotificationsDbContext, NotificationDefinitionGroupRecord, Guid>,
EfCoreRepository<INotificationsDefinitionDbContext, NotificationDefinitionGroupRecord, Guid>,
INotificationDefinitionGroupRecordRepository,
ITransientDependency
{
public EfCoreNotificationDefinitionGroupRecordRepository(
IDbContextProvider<INotificationsDbContext> dbContextProvider)
IDbContextProvider<INotificationsDefinitionDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

4
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionRecordRepository.cs

@ -6,12 +6,12 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.Notifications.EntityFrameworkCore;
public class EfCoreNotificationDefinitionRecordRepository :
EfCoreRepository<INotificationsDbContext, NotificationDefinitionRecord, Guid>,
EfCoreRepository<INotificationsDefinitionDbContext, NotificationDefinitionRecord, Guid>,
INotificationDefinitionRecordRepository,
ITransientDependency
{
public EfCoreNotificationDefinitionRecordRepository(
IDbContextProvider<INotificationsDbContext> dbContextProvider)
IDbContextProvider<INotificationsDefinitionDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

11
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/INotificationsDefinitionDbContext.cs

@ -0,0 +1,11 @@
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.Notifications.EntityFrameworkCore;
[IgnoreMultiTenancy]
[ConnectionStringName(AbpNotificationsDbProperties.ConnectionStringName)]
public interface INotificationsDefinitionDbContext : IEfCoreDbContext
{
}

19
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
@ -59,11 +60,26 @@ namespace LINGYUN.Abp.Notifications.EntityFrameworkCore
.HasDatabaseName("IX_Tenant_User_Notification_Name")
.IsUnique();
});
}
public static void ConfigureNotificationsDefinition(
this ModelBuilder builder,
Action<AbpNotificationsModelBuilderConfigurationOptions> optionsAction = null)
{
Check.NotNull(builder, nameof(builder));
if (!builder.IsHostOnlyDatabase())
{
return;
}
var options = new AbpNotificationsModelBuilderConfigurationOptions();
optionsAction?.Invoke(options);
builder.Entity<NotificationDefinitionGroupRecord>(b =>
{
b.ToTable(options.TablePrefix + "NotificationDefinitionGroups", options.Schema);
b.Property(p => p.Name)
.HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxNameLength)
.IsRequired();
@ -79,7 +95,6 @@ namespace LINGYUN.Abp.Notifications.EntityFrameworkCore
builder.Entity<NotificationDefinitionRecord>(b =>
{
b.ToTable(options.TablePrefix + "NotificationDefinitions", options.Schema);
b.Property(p => p.Name)
.HasMaxLength(NotificationDefinitionRecordConsts.MaxNameLength)
.IsRequired();

23
aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDefinitionDbContext.cs

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.Notifications.EntityFrameworkCore;
[ConnectionStringName(AbpNotificationsDbProperties.ConnectionStringName)]
public class NotificationsDefinitionDbContext : AbpDbContext<NotificationsDefinitionDbContext>, INotificationsDefinitionDbContext
{
public NotificationsDefinitionDbContext(DbContextOptions<NotificationsDefinitionDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetMultiTenancySide(MultiTenancySides.Host);
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigureNotificationsDefinition();
}
}

36
aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs

@ -175,24 +175,36 @@ public class EfCoreTenantRepository : EfCoreRepository<ISaasDbContext, Tenant, G
var tenantDbSet = dbContext.Set<Tenant>()
.IncludeDetails(includeDetails);
var queryable = tenantDbSet
tenantDbSet = tenantDbSet
.WhereIf(!filter.IsNullOrWhiteSpace(), u => u.Name.Contains(filter))
.OrderBy(sorting.IsNullOrEmpty() ? nameof(Tenant.Name) : sorting);
var combinedResult = await queryable
.Join(
editionDbSet,
o => o.EditionId,
i => i.Id,
(tenant, edition) => new { tenant, edition })
.Skip(skipCount)
.Take(maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
var combinedResult = await (from tenant in tenantDbSet
join edition in editionDbSet on tenant.EditionId equals edition.Id
into eg from e in eg.DefaultIfEmpty()
select new
{
Tenant = tenant,
Edition = e,
})
.Skip(skipCount)
.Take(maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
//var combinedResult = await tenantDbSet
// .Join(
// editionDbSet,
// o => o.EditionId,
// i => i.Id,
// (tenant, edition) => new { tenant, edition })
// .Skip(skipCount)
// .Take(maxResultCount)
// .ToListAsync(GetCancellationToken(cancellationToken));
return combinedResult.Select(s =>
{
s.tenant.Edition = s.edition;
return s.tenant;
s.Tenant.Edition = s.Edition;
return s.Tenant;
}).ToList();
}

2
aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs

@ -24,6 +24,8 @@ public class SaasDbContext : AbpDbContext<SaasDbContext>, ISaasDbContext
protected override void OnModelCreating(ModelBuilder builder)
{
builder.SetMultiTenancySide(MultiTenancySides.Host);
base.OnModelCreating(builder);
builder.ConfigureSaas();

Loading…
Cancel
Save