Initial commit
This commit is contained in:
39
Oqtane.Server/Repository/TenantContext.cs
Normal file
39
Oqtane.Server/Repository/TenantContext.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
using System;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public class TenantContext : DbContext
|
||||
{
|
||||
public virtual DbSet<Site> Site { get; set; }
|
||||
public virtual DbSet<Page> Page { get; set; }
|
||||
public virtual DbSet<PageModule> PageModule { get; set; }
|
||||
public virtual DbSet<Module> Module { get; set; }
|
||||
public virtual DbSet<User> User { get; set; }
|
||||
|
||||
private readonly Tenant tenant;
|
||||
|
||||
public TenantContext(ITenantRepository TenantRepository)
|
||||
{
|
||||
tenant = TenantRepository.GetTenant();
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(tenant.DBConnectionString
|
||||
.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString())
|
||||
);
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
if (tenant.DBSchema != "")
|
||||
{
|
||||
modelBuilder.HasDefaultSchema(tenant.DBSchema);
|
||||
}
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user