Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter not working #1256

Open
dorathoto opened this issue Oct 10, 2024 · 5 comments
Open

Filter not working #1256

dorathoto opened this issue Oct 10, 2024 · 5 comments

Comments

@dorathoto
Copy link

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 tennantID column (FK) is equal to my GUID variable

ex:

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 filterTennants = new SetupFilter("Tennants");
filterTennants.AddParameter("TennantId", DbType.Guid); 
filterTennants.AddWhere("TennantId", "Tennants", "TennantId");
setup.Filters.Add(filterTennants);


 var filterDevices = new SetupFilter("Devices");
 filterDevices .AddParameter("TennantId", DbType.Guid);
 filterDevices .AddWhere("TennantId", "Devices", "TennantId");
 setup.Filters.Add(filterDevices);

 var filterAudios = new SetupFilter("Audios");
 filterAudios.AddParameter("TennantId", DbType.Guid);
 filterAudios.AddWhere("TennantId", "Audios", "TennantId");
 setup.Filters.Add(filterAudios);

I've already tried sending the DbType.Guid type as the TableName ("TennantId", "Audios");

Here I define the created parameter called TennantID for my C# variable _myTennantId

var parameters = new SyncParameters
{
{ "TennantId", _myTennantId }
};

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 TennantIDs and not the one in my variable _myTennantId

@Mimetis
Copy link
Owner

Mimetis commented Oct 10, 2024

Can you provide a quick repro sample, like a sql script that will create the database with some rows, and a bit of code to reproduce the error ?

@dorathoto
Copy link
Author

Sure, I made a complete example
Create 2 MSSQL databases (Master and Local)
Enable Change Tracking
Create Seed by tennantId
Create Seed by Random Data.

Run the Sync Database by Dotmin creating the filter by tennant.
It does the sync but with all the data (Random and by tennant) I wanted the Local database to have only by TennantId == appSettings.jon

https://github.com/dorathoto/POC_DotMim.Sync.Sample

@Mimetis
Copy link
Owner

Mimetis commented Oct 11, 2024

Thanks for the detailed sample, it's helping a lot, appreciate !

Can you try to remove the "dbo." in all your declaration, like replacing from this:

            var setup = new SyncSetup("dbo.Tennants", "dbo.Audios", "dbo.Led", "dbo.LedEffect");

            setup.Tables["dbo.Tennants"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["dbo.Audios"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["dbo.Led"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["dbo.LedEffect"].SyncDirection = SyncDirection.DownloadOnly;

to this:

            var setup = new SyncSetup("Tennants", "Audios", "Led", "LedEffect");

            setup.Tables["Tennants"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["Audios"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["Led"].SyncDirection = SyncDirection.DownloadOnly;
            setup.Tables["LedEffect"].SyncDirection = SyncDirection.DownloadOnly;

And make another test.
Let me know if it's working better

@Mimetis
Copy link
Owner

Mimetis commented Oct 18, 2024

Is it working as expected now ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Mimetis @dorathoto and others