I'm using a very interesting package to sync between SQL Server.
As it's something simple, "Download Only", it behaves well and quickly.
Now I need to create a filter - something like
FROM Table_Name
WHERE tenantID = @myVariable
I'm following the documentation here: https://dotmimsync.readthedocs.io/Filters.html
Apparently the logic is simple and perfect, but I can't run the filter, it syncs but doesn't filter
I have several tables and I want to create a filter, where the tenantID
column (FK) is equal to my GUID variable value.
For example:
var setup = new SyncSetup("dbo.Tennants", "dbo.Devices", "dbo.Audios", et cetera...)
setup.Tables["dbo.Tennants"].SyncDirection = SyncDirection.DownloadOnly;
setup.Tables["dbo.Devices"].SyncDirection = SyncDirection.DownloadOnly;
setup.Tables["dbo.Audios"].SyncDirection = SyncDirection.DownloadOnly;
Here the filters start:
var filterTenants = new SetupFilter("Tenants");
filterTenants.AddParameter("TenantId", DbType.Guid);
filterTenants.AddWhere("TenantId", "Tenants", "TenantId");
setup.Filters.Add(filterTenants);
var filterDevices = new SetupFilter("Devices");
filterDevices.AddParameter("TenantId", DbType.Guid);
filterDevices.AddWhere("TenantId", "Devices", "TenantId");
setup.Filters.Add(filterDevices);
var filterAudios = new SetupFilter("Audios");
filterAudios.AddParameter("TenantId", DbType.Guid);
filterAudios.AddWhere("TenantId", "Audios", "TenantId");
setup.Filters.Add(filterAudios);
I've already tried sending the DbType.Guid type as the TableName ("TenantId", "Audios");
Here I define the created parameter called TenantID
for my C# variable _myTenantId
var parameters = new SyncParameters
{
{ "TenantId", _myTenantId }
};
and at the end I execute:
var result = await agent.SynchronizeAsync(setup, parameters, progress);
Of course the code is much larger, error handling, etc., but I don't believe that this influences it.
It synchronizes all TenantID
s and not the one in my variable _myTenantId
.
I made a working example to test this problem
Master
and Local
)tenantId
create seed by random dataI discovered that you can't send the schema name along with it. Even though it's stated in the documentation.
instead of:
setup.Tables["dbo.Tennants"].SyncDirection = SyncDirection.DownloadOnly;
the correct one:
setup.Tables["Tennants"].SyncDirection = SyncDirection.DownloadOnly;
Subtle, but the error didn't show this, I discovered it through the author's own answer.