Selecting cols to compare and updating certain cols only

hemantgaurhemantgaur Posts: 27
Hi I am new to Red Gate API, so it might sound like a basic question.

Table T1 has following columns. C1, C2, C3, C4, C5, C6.

I want to compare only C2, C3, C4 columns with destination. I want to synchronize only these columns if they have a different value and ignore C5 and C6. C1 is the primary key.

I want to do it through the API and not the interface. If you can just explain that will be fine, if you have a sample code, that would be even better.

There is some urgency, so if you can expedite it, it will be great.

Comments

  • Thanks for your post.

    When you first map the tables together, all the columns will be mapped by default - e.g.
    mappings.CreateMappings(db1.Tables, db2.Tables);
    

    You can then exclude specific columns by setting the FieldMapping include property to 'false'.

    We have an example on our website of excluding a column with a specific name from all tables in the project, but you can easily change it to exclude columns from a specific table.

    You can find the example here

    I hope this helps.
    Chris
  • Hi, Thank you for your reply. That explains how I select columns for comparison. The second part of my question was how do I select the columns that I want to update. I do not want to carry forward the values of certain columns. i.e. I want to exclude some columns using the API.

    Thank you.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello,

    You can omit columns using the mappings in much the same way as you would omit tables, but there are also filters and Selection Delegate methods that you can use to filter the columns that will be synchronized after they had already been included in the actual comparison.

    Because there are so many ways of filtering the comparison and the synchronization, I wrote a list of the merits of each method and put it on our wiki:

    http://labs.red-gate.com/index.php/Filt ... a_overview

    I think that the "FieldMapping.Remove" method could be the best option to use from your description.
Sign In or Register to comment.