Hello,
We have a host and a tenant database. When we run update-database for the Tenant, it will add the settings: update-database -verbose -projectname MyCompanyName.AbpZeroTemplate.EntityFramework -startupprojectname MyCompanyName.AbpZeroTemplate.Web -configuration MyCompanyName.AbpZeroTemplate.AbpZeroTemplateTenant.Configuration We now have settings and that is great. When we run this again, the settings are duplicated. We have traced this to DefaultSettingsCreator.cs > AddSettingIfNotExists. It looks like this:
private void AddSettingIfNotExists(string name, string value, int? tenantId = null)
{
if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
{
return;
}
_context.Settings.Add(new Setting(tenantId, null, name, value));
_context.SaveChanges();
}
In debugging this, it appears that _context.settings always has a count of 0. I thought this might be the wrong context, but the Add method works. Does anybody know what could cause this situation?
9 Answer(s)
-
0
Hi @careLearning,
Do you use ASP.NET MVC 5.x or ASP.NET Core version ? Because seed method works differently in both verions.
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Dear @ismcagdas,
We are using the ASP.NET MVC 5.x the version.
Regards
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thanks for the information, I will check this and get back to you in a short time.
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thank you for the response. Have you discovered any new information?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
It might be related to EntityFramework.DynamicFilters. Can you share it's version and version of ABP package as well ?
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @ismcagdas,
This is from our packages.config file: <package id="Abp" version="2.1.3" targetFramework="net461" /> ... <package id="EntityFramework.DynamicFilters" version="2.7.0" targetFramework="net461" />
Thank you for your help and effort.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
This is same with ABP. But still it might be related to EntityFramework.DynamicFilters.
Can you share your project with us, so we can test and fix this problem. You can send your project to <a href="mailto:[email protected]">[email protected]</a>.
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi!
I'm curious whether there are any updates on this issue!?
I think I encounter the same behaviour when seeding the database! They way I do it is to first query the DB for an element with a certain ID using the following:
var result = context.TableName.Find(id)If the result is null I create a new element with a certain Tenant-Id and insert it to the Table. Adding the new element works as expected!
But the next time I run the seed-method the result will be null and a new element will be inserted, again. I think this has something to do with the Tenant-Id. Since the Tenant-Id is not null, the query won't have any result - the host just doesn't have any permission to read a tenant's element.
I also have the same seed-method with the only difference in the Tenant-Id being null. Here everything works as expected!
Is there a way to access the DB and query elements regardless of their Tenant-Id?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Ah, i just found out how to do it myself 8-)
Using the following line before quering the DB did the trick for me:
_context.CurrentUnitOfWorkProvider.Current.DisableFilter(AbpDataFilters.MayHaveTenant);Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)