Initial commit
This commit is contained in:
33
Oqtane.Server/Repository/ContextBase.cs
Normal file
33
Oqtane.Server/Repository/ContextBase.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
using System;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public class ContextBase : DbContext
|
||||
{
|
||||
private Tenant tenant;
|
||||
|
||||
public ContextBase(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