SubSonic 3 / ActiveRecord - an easy way to compare two records?

With SubSonic 3 / ActiveRecord, there is an easy way to compare two records without comparing each column by column. For example, I need a function that does something like this (without having to write a custom mapper for every table in my database):

public partial class MyTable
{
    public IList<SubSonic.Schema.IColumn> Compare(MyTable m)
    {
        IList<SubSonic.Schema.IColumn> columnsThatDontMatch = new...;
        if (this.Field1 != m.Field1)
        {
            columnsThatDontMatch.add(Field1_Column);
        }
        if (this.Field2 != m.Field2)
        {
            columnsThatDontMatch.add(Field2_Column);
        }
        ...
        return columnsThatDontMatch;
    }
}

      

In the end, I really need a function that tests equality between two strings, excluding the primary key columns. The pseudo code above is a more general form of this. I believe that as soon as I get the columns that don't match, I can check if any of the columns are primary key fields.

I went through the Columns property without finding anything I can use. Ideally, the solution would be something I can toss into a t4 file and generate for all my tables in the database.

+2


source to share


1 answer


The best way, if using SQL Server as a backend, as this can be auto-populated, is to create a derived column that has a definition that uses CHECKSUM to hash the values ā€‹ā€‹of the "selected" columns to form uniqueness beyond the primary key.



EDIT: if you are not using SQL Server then this hashing must be done in code on save, edit the line.

+1


source







All Articles