mirror of https://github.com/abpframework/abp.git
4 changed files with 70 additions and 5 deletions
@ -0,0 +1,29 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.SettingManagement.EntityFrameworkCore |
||||
|
{ |
||||
|
[ConnectionStringName("AbpSettingManagement")] |
||||
|
public class SettingManagementDbContext : AbpDbContext<SettingManagementDbContext>, ISettingManagementDbContext |
||||
|
{ |
||||
|
public static string TablePrefix { get; set; } = AbpSettingManagementConsts.DefaultDbTablePrefix; |
||||
|
|
||||
|
public static string Schema { get; set; } = AbpSettingManagementConsts.DefaultDbSchema; |
||||
|
|
||||
|
public DbSet<Setting> Settings { get; set; } |
||||
|
|
||||
|
public SettingManagementDbContext(DbContextOptions<SettingManagementDbContext> options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected override void OnModelCreating(ModelBuilder builder) |
||||
|
{ |
||||
|
base.OnModelCreating(builder); |
||||
|
|
||||
|
builder.ConfigureSettingManagement(TablePrefix, Schema); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.SettingManagement.EntityFrameworkCore |
||||
|
{ |
||||
|
public static class SettingManagementDbContextModelBuilderExtensions |
||||
|
{ |
||||
|
//TODO: Instead of getting parameters, get a action of SettingManagementModelBuilderConfigurationOptions like other modules
|
||||
|
public static void ConfigureSettingManagement( |
||||
|
[NotNull] this ModelBuilder builder, |
||||
|
[CanBeNull] string tablePrefix = AbpSettingManagementConsts.DefaultDbTablePrefix, |
||||
|
[CanBeNull] string schema = AbpSettingManagementConsts.DefaultDbSchema) |
||||
|
{ |
||||
|
Check.NotNull(builder, nameof(builder)); |
||||
|
|
||||
|
if (tablePrefix == null) |
||||
|
{ |
||||
|
tablePrefix = ""; |
||||
|
} |
||||
|
|
||||
|
builder.Entity<Setting>(b => |
||||
|
{ |
||||
|
b.ToTable(tablePrefix + "Settings", schema); |
||||
|
|
||||
|
b.Property(x => x.Name).HasMaxLength(SettingConsts.MaxNameLength).IsRequired(); |
||||
|
b.Property(x => x.Value).HasMaxLength(SettingConsts.MaxValueLength).IsRequired(); |
||||
|
b.Property(x => x.ProviderName).HasMaxLength(SettingConsts.MaxProviderNameLength); |
||||
|
b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength); |
||||
|
|
||||
|
b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue