I want to seed some tenant related data when a Tenant is created.
This is where I think I should seed data : protected override void Seed(EntityFramework.MajesticDbContext context) { context.DisableAllFilters();
context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
context.EventBus = NullEventBus.Instance;
if (Tenant == null)
{
//Host seed
new InitialHostDbBuilder(context).Create();
//Default tenant seed (in host database).
new DefaultTenantBuilder(context).Create();
new TenantRoleAndUserBuilder(context, 1).Create();
}
else { //You can add seed for tenant databases using Tenant property... new InitialPeopleCreator(context).Create(); }
I need to call this class InitialPeopleCreator.cs in the else block, but this part of code is never called? How do I do this?
3 Answer(s)
-
0
Hi,
This will only work if you are creating tenant with a seperate database. So, I suggest to use a specific class like this one <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/MultiTenancy/TenantManager.cs#L162">https://github.com/aspnetzero/aspnet-ze ... er.cs#L162</a> we have used for creating a demo data for each created tenant.
-
0
As far from my research in MultiTenantMigrateExecuterclass I found that, this else block will be called only when we configure "connectionString" for that Tenant in AbpTenants table. If that connection string is not null, then this else block is been called. Now my question here is, I set the connection string as "Server=localhost; Database=Majestic; Trusted_Connection=True;" (without quotes) in the table. But when I debug then I get this error: "System.FormatException: 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. '" while trying to log the connection string using "Log.Write("Connection string : " + SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString));"
Can you let me know what format of the connection string does it is looking for? I was using the samething that aspnetzero provides
-
0
You shouldn't set the connection string directly on the table. You need to set it on the tenan entity while creating a new tenant. In that case, the migrations and seed data will work.