Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Exclude columns feature#1330

Open
wismna wants to merge 3 commits intoMimetis:masterfrom
dispatchscience:master
Open

Add Exclude columns feature#1330
wismna wants to merge 3 commits intoMimetis:masterfrom
dispatchscience:master

Conversation

@wismna
Copy link

@wismna wismna commented Jul 30, 2025

Currently, when no columns are specified in the setup, it will sync all the table columns.

This adds an column exclusion feature, so that all columns except the excluded ones will be synchronized. It allows for simpler configuration when tables have many columns and we only want to exclude a few.
The excluded columns will not be taken into account at all if columns are specified in the setup.

@Mimetis
Copy link
Owner

Mimetis commented Aug 1, 2025

hi @wismna

Thanks for the contribution ! Appreciate !

That being said, some remarks:

  1. We need tests :)

  2. What happens if we have this code:

var setup = new SyncSetup("Customer");

// Add columns
setup.Tables["Employee"].Columns.AddRange("CustomerID", "FirstName", "LastName", "Title", "Suffix", "CompanyName", "rowGuid");

setup.Tables["Employee"].Columns.ExcludeRange("rowGuid", "LastModifiedDate");

I know this example is kind of stupid, but if you think about some algorithm where colums are built using a loop or any dynamic routine, we can end up with such situation

  1. For adding columns, we have 2 main method : SetupColumns.Add(string item) and SetupColumns.AddRange(params string[] columnsName)

If you look carefully SetupColumns.Add(string item) method (called from AddRange) is here to ensure columns name is parsed to avoid incorrect character and then ensure column exists.
Even if we are excluding a column, we need to ensure that these two verifications are done.
Indeed if someone mispells a column name to be excluded, the column will not be excluded eventually...

By the way in method Add(), you are checking ExcludedCollection, and that makes no sense to me !

@Mimetis Mimetis self-requested a review August 1, 2025 15:02
@wismna
Copy link
Author

wismna commented Aug 1, 2025

Thanks for the contribution ! Appreciate !

You're welcome !

  1. We need tests :)

Indeed we do, I'll get on it.

  1. What happens if we have this code:
var setup = new SyncSetup("Customer");

// Add columns
setup.Tables["Employee"].Columns.AddRange("CustomerID", "FirstName", "LastName", "Title", "Suffix", "CompanyName", "rowGuid");

setup.Tables["Employee"].Columns.ExcludeRange("rowGuid", "LastModifiedDate");

I know this example is kind of stupid, but if you think about some algorithm where colums are built using a loop or any dynamic routine, we can end up with such situation

Well, I asked myself that same question, and I'm not sure there is a "right" answer. The way I see it, we have three possibilities:

  • included columns win
  • excluded columns win
  • we raise an error, which is what I tried to implement (cf. last remark)

What's your opinion on the subject ?

  1. For adding columns, we have 2 main method : SetupColumns.Add(string item) and SetupColumns.AddRange(params string[] columnsName)

If you look carefully SetupColumns.Add(string item) method (called from AddRange) is here to ensure columns name is parsed to avoid incorrect character and then ensure column exists. Even if we are excluding a column, we need to ensure that these two verifications are done. Indeed if someone mispells a column name to be excluded, the column will not be excluded eventually...

Oh, right, I missed that ! I'll fix it.

By the way in method Add(), you are checking ExcludedCollection, and that makes no sense to me !

Perhaps I did not do that properly, but it's related to your second point: if we try to add a column that is already excluded, we raise an error as it kind of made no sense for me to have the same column both included and excluded.

@Mimetis
Copy link
Owner

Mimetis commented Aug 2, 2025

I know this example is kind of stupid, but if you think about some algorithm where colums are built using a loop or any dynamic routine, we can end up with such situation

Well, I asked myself that same question, and I'm not sure there is a "right" answer. The way I see it, we have three possibilities:

  • included columns win
  • excluded columns win
  • we raise an error, which is what I tried to implement (cf. last remark)

What's your opinion on the subject ?

I guess we can use a kind of merge method

  • If you Include columns, then exclude columns, excluding is the last action and is the winner :
    Example: Include C1 C2 C3 C4 then Exclude C2 => C1 C3 C4 is the final result

  • if you exclude columns then include, including is the last action and is the winner
    Example: Exclude C1 C2 then Include C2 C3 C4 C5 => C2 C3 C4 C5 is the winner

By the way, raising an error can also be a solution ... I don't know !

By the way in method Add(), you are checking ExcludedCollection, and that makes no sense to me !

Perhaps I did not do that properly, but it's related to your second point: if we try to add a column that is already excluded, we raise an error as it kind of made no sense for me to have the same column both included and excluded.

True !

@wismna
Copy link
Author

wismna commented Sep 9, 2025

Hi !

So, I updated the code. After our discussions, I figured that I would implement it in a way where the last operation wins, as you described here:

if you Include columns, then exclude columns, excluding is the last action and is the winner :
Example: Include C1 C2 C3 C4 then Exclude C2 => C1 C3 C4 is the final result

if you exclude columns then include, including is the last action and is the winner
Example: Exclude C1 C2 then Include C2 C3 C4 C5 => C2 C3 C4 C5 is the winner

Also, I added unit tests to cover these cases and used the same code to parse column name.

Let me know what you think !

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

Successfully merging this pull request may close these issues.

2 participants