mirror of https://github.com/abpframework/abp.git
6 changed files with 62 additions and 26 deletions
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore |
||||
|
{ |
||||
|
public interface IEfCoreDbContext |
||||
|
{ |
||||
|
int SaveChanges(); |
||||
|
|
||||
|
int SaveChanges(bool acceptAllChangesOnSuccess); |
||||
|
|
||||
|
DbSet<T> Set<T>() |
||||
|
where T: class; |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,9 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using Microsoft.Extensions.Options; |
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.Data; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.MultiTenancy; |
|
||||
|
|
||||
namespace Volo.Abp.Data.MultiTenancy |
namespace Volo.Abp.MultiTenancy |
||||
{ |
{ |
||||
[Dependency(ReplaceServices = true)] |
[Dependency(ReplaceServices = true)] |
||||
public class MultiTenantConnectionStringResolver : DefaultConnectionStringResolver |
public class MultiTenantConnectionStringResolver : DefaultConnectionStringResolver |
||||
@ -0,0 +1,12 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.MultiTenancy.EntityFrameworkCore |
||||
|
{ |
||||
|
public interface IMultiTenancyDbContext : IEfCoreDbContext |
||||
|
{ |
||||
|
DbSet<Tenant> Tenants { get; set; } |
||||
|
|
||||
|
DbSet<TenantConnectionString> TenantConnectionStrings { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.MultiTenancy.EntityFrameworkCore |
||||
|
{ |
||||
|
public static class MultiTenancyDbContextModelCreatingExtensions |
||||
|
{ |
||||
|
public static void ConfigureAbpMultiTenancy(this IMultiTenancyDbContext dbContext, ModelBuilder builder) |
||||
|
{ |
||||
|
builder.Entity<Tenant>(b => |
||||
|
{ |
||||
|
b.ToTable("MtTenants"); //TODO: Make all table and schema names changeable
|
||||
|
|
||||
|
b.Property(t => t.Name).IsRequired().HasMaxLength(TenantConsts.MaxNameLength); |
||||
|
|
||||
|
b.HasMany(u => u.ConnectionStrings).WithOne().HasForeignKey(uc => uc.TenantId).IsRequired(); |
||||
|
|
||||
|
b.HasIndex(u => u.Name); |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<TenantConnectionString>(b => |
||||
|
{ |
||||
|
b.ToTable("MtTenantConnectionStrings"); |
||||
|
|
||||
|
b.Property(cs => cs.Name).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxNameLength); |
||||
|
b.Property(cs => cs.Value).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxValueLength); |
||||
|
|
||||
|
b.HasIndex(cs => cs.TenantId); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue