diff --git a/aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs b/aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs index 245a8bbb7..3b64d1c37 100644 --- a/aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs +++ b/aspnet-core/migrations/LY.MicroService.RealtimeMessage.DbMigrator/EntityFrameworkCore/RealtimeMessageMigrationsDbContext.cs @@ -20,6 +20,7 @@ public class RealtimeMessageMigrationsDbContext : AbpDbContext(); options.AddRepository(); - options.AddRepository(); - options.AddRepository(); options.AddRepository(); options.AddRepository(); }); + + context.Services.AddAbpDbContext(options => + { + options.AddDefaultRepositories(); + + options.AddRepository(); + options.AddRepository(); + }); } } diff --git a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionGroupRecordRepository.cs b/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionGroupRecordRepository.cs index fc08242a0..5981de1c9 100644 --- a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionGroupRecordRepository.cs +++ b/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, + EfCoreRepository, INotificationDefinitionGroupRecordRepository, ITransientDependency { public EfCoreNotificationDefinitionGroupRecordRepository( - IDbContextProvider dbContextProvider) + IDbContextProvider dbContextProvider) : base(dbContextProvider) { } diff --git a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionRecordRepository.cs b/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionRecordRepository.cs index 65ed69c5c..8686d64a9 100644 --- a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/EfCoreNotificationDefinitionRecordRepository.cs +++ b/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, + EfCoreRepository, INotificationDefinitionRecordRepository, ITransientDependency { public EfCoreNotificationDefinitionRecordRepository( - IDbContextProvider dbContextProvider) + IDbContextProvider dbContextProvider) : base(dbContextProvider) { } diff --git a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/INotificationsDefinitionDbContext.cs b/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/INotificationsDefinitionDbContext.cs new file mode 100644 index 000000000..22230257d --- /dev/null +++ b/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 +{ +} diff --git a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs b/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs index 8e6db1b92..4c5b51d4e 100644 --- a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDbContextModelCreatingExtensions.cs +++ b/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 optionsAction = null) + { + Check.NotNull(builder, nameof(builder)); + + if (!builder.IsHostOnlyDatabase()) + { + return; + } + + var options = new AbpNotificationsModelBuilderConfigurationOptions(); + + optionsAction?.Invoke(options); builder.Entity(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(b => { b.ToTable(options.TablePrefix + "NotificationDefinitions", options.Schema); - b.Property(p => p.Name) .HasMaxLength(NotificationDefinitionRecordConsts.MaxNameLength) .IsRequired(); diff --git a/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDefinitionDbContext.cs b/aspnet-core/modules/notifications/LINGYUN.Abp.Notifications.EntityFrameworkCore/LINGYUN/Abp/Notifications/EntityFrameworkCore/NotificationsDefinitionDbContext.cs new file mode 100644 index 000000000..683382198 --- /dev/null +++ b/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, INotificationsDefinitionDbContext +{ + public NotificationsDefinitionDbContext(DbContextOptions options) + : base(options) + { + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.SetMultiTenancySide(MultiTenancySides.Host); + + base.OnModelCreating(modelBuilder); + + modelBuilder.ConfigureNotificationsDefinition(); + } +} diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs index db423ab7d..345999820 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs @@ -175,24 +175,36 @@ public class EfCoreTenantRepository : EfCoreRepository() .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(); } diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs index b3e9b95f4..abcf2e657 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/SaasDbContext.cs @@ -24,6 +24,8 @@ public class SaasDbContext : AbpDbContext, ISaasDbContext protected override void OnModelCreating(ModelBuilder builder) { + builder.SetMultiTenancySide(MultiTenancySides.Host); + base.OnModelCreating(builder); builder.ConfigureSaas();