Merge pull request #7531 from abpframework/auto-merge/rel-4-2/144

Merge branch dev with rel-4.2
pull/7538/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit ffe4e8c51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,10 +1,72 @@
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.MultiTenancy;
namespace Microsoft.EntityFrameworkCore
{
public static class AbpModelBuilderExtensions
{
private const string ModelDatabaseProviderAnnotationKey = "_Abp_DatabaseProvider";
private const string ModelMultiTenancySideAnnotationKey = "_Abp_MultiTenancySide";
#region MultiTenancySide
public static void SetMultiTenancySide(
this ModelBuilder modelBuilder,
MultiTenancySides side)
{
modelBuilder.Model.SetAnnotation(ModelMultiTenancySideAnnotationKey, side);
}
public static MultiTenancySides GetMultiTenancySide(this ModelBuilder modelBuilder)
{
var value = modelBuilder.Model[ModelMultiTenancySideAnnotationKey];
if (value == null)
{
return MultiTenancySides.Both;
}
return (MultiTenancySides) value;
}
/// <summary>
/// Returns true if this is a database schema that is used by the host
/// but can also be shared with the tenants.
/// </summary>
public static bool IsHostDatabase(this ModelBuilder modelBuilder)
{
return modelBuilder.GetMultiTenancySide().HasFlag(MultiTenancySides.Host);
}
/// <summary>
/// Returns true if this is a database schema that is used by the tenants
/// but can also be shared with the host.
/// </summary>
public static bool IsTenantDatabase(this ModelBuilder modelBuilder)
{
return modelBuilder.GetMultiTenancySide().HasFlag(MultiTenancySides.Tenant);
}
/// <summary>
/// Returns true if this is a database schema that is only used by the host
/// and should not contain tenant-only tables.
/// </summary>
public static bool IsHostOnlyDatabase(this ModelBuilder modelBuilder)
{
return modelBuilder.GetMultiTenancySide() == MultiTenancySides.Host;
}
/// <summary>
/// Returns true if this is a database schema that is only used by tenants.
/// and should not contain host-only tables.
/// </summary>
public static bool IsTenantOnlyDatabase(this ModelBuilder modelBuilder)
{
return modelBuilder.GetMultiTenancySide() == MultiTenancySides.Tenant;
}
#endregion
#region DatabaseProvider
public static void SetDatabaseProvider(
this ModelBuilder modelBuilder,
@ -61,7 +123,7 @@ namespace Microsoft.EntityFrameworkCore
{
modelBuilder.SetDatabaseProvider(EfCoreDatabaseProvider.InMemory);
}
public static bool IsUsingInMemory(
this ModelBuilder modelBuilder)
{
@ -73,7 +135,7 @@ namespace Microsoft.EntityFrameworkCore
{
modelBuilder.SetDatabaseProvider(EfCoreDatabaseProvider.Cosmos);
}
public static bool IsUsingCosmos(
this ModelBuilder modelBuilder)
{
@ -85,11 +147,13 @@ namespace Microsoft.EntityFrameworkCore
{
modelBuilder.SetDatabaseProvider(EfCoreDatabaseProvider.Firebird);
}
public static bool IsUsingFirebird(
this ModelBuilder modelBuilder)
{
return modelBuilder.GetDatabaseProvider() == EfCoreDatabaseProvider.Firebird;
}
#endregion
}
}
}

@ -48,11 +48,19 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
DbContextTransaction.Dispose();
}
public Task RollbackAsync(CancellationToken cancellationToken)
public async Task RollbackAsync(CancellationToken cancellationToken)
{
return DbContextTransaction.RollbackAsync(
CancellationTokenProvider.FallbackToProvider(cancellationToken)
);
await DbContextTransaction.RollbackAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken));
foreach (var dbContext in AttendedDbContexts)
{
if (dbContext.As<DbContext>().HasRelationalTransactionManager())
{
continue; //Relational databases use the shared transaction
}
await dbContext.Database.RollbackTransactionAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken));
}
}
}
}

@ -191,7 +191,10 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
}
else
{
dbContext.Database.BeginTransaction(); //TODO: Why not using the new created transaction?
/* No need to store the returning IDbContextTransaction for non-relational databases
* since EfCoreTransactionApi will handle the commit/rollback over the DbContext instance.
*/
dbContext.Database.BeginTransaction();
}
activeTransaction.AttendedDbContexts.Add(dbContext);
@ -236,7 +239,10 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
}
else
{
await dbContext.Database.BeginTransactionAsync(GetCancellationToken()); //TODO: Why not using the new created transaction?
/* No need to store the returning IDbContextTransaction for non-relational databases
* since EfCoreTransactionApi will handle the commit/rollback over the DbContext instance.
*/
await dbContext.Database.BeginTransactionAsync(GetCancellationToken());
}
activeTransaction.AttendedDbContexts.Add(dbContext);

@ -12,13 +12,18 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new BackgroundJobsModelBuilderConfigurationOptions(
BackgroundJobsDbProperties.DbTablePrefix,
BackgroundJobsDbProperties.DbSchema
);
optionsAction?.Invoke(options);
builder.Entity<BackgroundJobRecord>(b =>
{
b.ToTable(options.TablePrefix + "BackgroundJobs", options.Schema);
@ -32,9 +37,9 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore
b.Property(x => x.LastTryTime);
b.Property(x => x.IsAbandoned).HasDefaultValue(false);
b.Property(x => x.Priority).HasDefaultValue(BackgroundJobPriority.Normal);
b.HasIndex(x => new { x.IsAbandoned, x.NextTryTime });
});
}
}
}
}

@ -20,6 +20,11 @@ namespace Volo.Blogging.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new BloggingModelBuilderConfigurationOptions(
BloggingDbProperties.DbTablePrefix,
BloggingDbProperties.DbSchema

@ -16,6 +16,11 @@ namespace Volo.Docs.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new DocsModelBuilderConfigurationOptions(
DocsDbProperties.DbTablePrefix,
DocsDbProperties.DbSchema
@ -69,4 +74,4 @@ namespace Volo.Docs.EntityFrameworkCore
});
}
}
}
}

@ -12,6 +12,11 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new FeatureManagementModelBuilderConfigurationOptions(
FeatureManagementDbProperties.DbTablePrefix,
FeatureManagementDbProperties.DbSchema
@ -34,4 +39,4 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
});
}
}
}
}

@ -152,18 +152,21 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasIndex(uc => uc.RoleId);
});
builder.Entity<IdentityClaimType>(b =>
if (builder.IsHostDatabase())
{
b.ToTable(options.TablePrefix + "ClaimTypes", options.Schema);
builder.Entity<IdentityClaimType>(b =>
{
b.ToTable(options.TablePrefix + "ClaimTypes", options.Schema);
b.ConfigureByConvention();
b.ConfigureByConvention();
b.Property(uc => uc.Name).HasMaxLength(IdentityClaimTypeConsts.MaxNameLength)
.IsRequired(); // make unique
b.Property(uc => uc.Regex).HasMaxLength(IdentityClaimTypeConsts.MaxRegexLength);
b.Property(uc => uc.RegexDescription).HasMaxLength(IdentityClaimTypeConsts.MaxRegexDescriptionLength);
b.Property(uc => uc.Description).HasMaxLength(IdentityClaimTypeConsts.MaxDescriptionLength);
});
b.Property(uc => uc.Name).HasMaxLength(IdentityClaimTypeConsts.MaxNameLength)
.IsRequired(); // make unique
b.Property(uc => uc.Regex).HasMaxLength(IdentityClaimTypeConsts.MaxRegexLength);
b.Property(uc => uc.RegexDescription).HasMaxLength(IdentityClaimTypeConsts.MaxRegexDescriptionLength);
b.Property(uc => uc.Description).HasMaxLength(IdentityClaimTypeConsts.MaxDescriptionLength);
});
}
builder.Entity<OrganizationUnit>(b =>
{
@ -233,22 +236,23 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.HasIndex(x => new { x.TenantId, x.UserId });
});
builder.Entity<IdentityLinkUser>(b =>
if (builder.IsHostDatabase())
{
b.ToTable(options.TablePrefix + "LinkUsers", options.Schema);
b.ConfigureByConvention();
b.HasIndex(x => new
builder.Entity<IdentityLinkUser>(b =>
{
UserId = x.SourceUserId,
TenantId = x.SourceTenantId,
LinkedUserId = x.TargetUserId,
LinkedTenantId = x.TargetTenantId
}).IsUnique();
});
b.ToTable(options.TablePrefix + "LinkUsers", options.Schema);
b.ConfigureByConvention();
b.HasIndex(x => new
{
UserId = x.SourceUserId,
TenantId = x.SourceTenantId,
LinkedUserId = x.TargetUserId,
LinkedTenantId = x.TargetTenantId
}).IsUnique();
});
}
}
}
}

@ -19,6 +19,11 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new IdentityServerModelBuilderConfigurationOptions(
AbpIdentityServerDbProperties.DbTablePrefix,
AbpIdentityServerDbProperties.DbSchema

@ -27,6 +27,11 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new SettingManagementModelBuilderConfigurationOptions(
AbpSettingManagementDbProperties.DbTablePrefix,
AbpSettingManagementDbProperties.DbSchema
@ -44,7 +49,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
if (builder.IsUsingOracle()) { SettingConsts.MaxValueLengthValue = 2000; }
b.Property(x => x.Value).HasMaxLength(SettingConsts.MaxValueLengthValue).IsRequired();
b.Property(x => x.ProviderName).HasMaxLength(SettingConsts.MaxProviderNameLength);
b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength);
@ -52,4 +57,4 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
});
}
}
}
}

@ -13,6 +13,11 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
if (builder.IsTenantOnlyDatabase())
{
return;
}
var options = new AbpTenantManagementModelBuilderConfigurationOptions(
AbpTenantManagementDbProperties.DbTablePrefix,
AbpTenantManagementDbProperties.DbSchema
@ -46,4 +51,4 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
});
}
}
}
}

@ -6,6 +6,7 @@
@using Volo.Abp.Users
@inject IHtmlLocalizer<MyProjectNameResource> L
@inject ICurrentUser CurrentUser
<abp-card>
<abp-card-header>Welcome</abp-card-header>
<abp-card-body>

@ -7,11 +7,20 @@
@inject IStringLocalizer<AbpUiResource> Localizer
@inject ICurrentUser CurrentUser
@if (!CurrentUser.IsAuthenticated)
{
<a href="~/Account/Login">@Localizer["Login"]</a>
}
else
{
<span>Welcome: @CurrentUser.UserName</span>
}
<abp-card>
<abp-card-header>Welcome</abp-card-header>
<abp-card-body>
@if (!CurrentUser.IsAuthenticated)
{
<a href="~/Account/Login">@Localizer["Login"]</a>
}
else
{
<span>Welcome: @CurrentUser.UserName</span>
}
<hr />
<p class="text-right"><a href="https://abp.io?ref=tmpl" target="_blank">abp.io</a></p>
</abp-card-body>
</abp-card>

@ -16,7 +16,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Menus
private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
{
//Add main menu items.
context.Menu.AddItem(new ApplicationMenuItem(MyProjectNameMenus.Prefix, displayName: "MyProjectName", "~/MyProjectName", icon: "fa fa-globe"));
context.Menu.AddItem(new ApplicationMenuItem(MyProjectNameMenus.Prefix, displayName: "MyProjectName", "/MyProjectName", icon: "fa fa-globe"));
return Task.CompletedTask;
}

Loading…
Cancel
Save