0
andmattia created
I try to add some static data on Seed method but I want to add row only if a feature is enable. I try but I not find how can get feature from database if i call
var featureSetting in allFeature.Where(t=> t.TenantId == tenant.Id).ToList()
it's always empty
5 Answer(s)
-
0
Hi,
Can you paste the whole code. And be sure you are querying against to the host database, not tenant database, because feature settings are stored in the host database.
-
0
this is the full code
private void CreateDefaultTemplate() { var tenants = _context.Tenants.ToList(); var allFeature = _context.TenantFeatureSettings.ToList(); foreach (var tenant in tenants) { foreach (var featureSetting in allFeature.Where(t=> t.TenantId == tenant.Id).ToList() ) { foreach (var template in InitialTemplates) { if (featureSetting.Name == template.ApplicationName) { template.TenantId = tenant.Id; AddTemplateIfNotExists(template); } } } } }
-
0
Your code seems fine. Check this:
- Is that code running in the host db (if you are using tenant per db)?
- Is _context.TenantFeatureSettings.ToList(); returns the true list?
-
0
I try and the list is empty (0 element).
i call my method from InitialHostDbBuilder
-
0
I found a solution. I check in Tenant but is setted on edition!
if(!tenant.EditionId.HasValue) continue; var ed = _context.Editions.FirstOrDefault(t => t.Id == tenant.EditionId.Value); var allFeature = _context.EditionFeatureSettings.Where(t=>t.EditionId == ed.Id).ToList(); for(....)