0
carelearning created
Hello,
We are trying to get the tenant.Id in the Seed(AbpZeroTemplateTenantDbContext context) method. We are currently doing it as below:
protected override void Seed(AbpZeroTemplateTenantDbContext context)
{
//Data Source=(localdb)\projectsv13; Initial Catalog=abp_tenant_name;
var tenancyName = new SqlConnectionStringBuilder(context.Database.Connection.ConnectionString)
.InitialCatalog.TrimStart(CustomConsts.DatabasePrefix.ToCharArray());
// prefix: abp_ so tenant name is tenant_name
var hostContext = new AbpZeroTemplateDbContext();
var tenant = hostContext.Tenants.SingleOrDefault(t => t.TenancyName == tenancyName);
var tenantId = 0;
if (tenant != null)
tenantId = tenant.Id;
var initialTenantDbBuilder = new InitialTenantDbBuilder(context);
initialTenantDbBuilder.Create(tenantId);
context.SaveChanges();
}
Is there a better or more simple way to do this?
Thank you for your time and effort.
1 Answer(s)
-
0
Hi,
When you are doing is fine. You need to query it from context.