views:

62

answers:

2

I would like to use this generic CompareObjects class but it seems that the Subsonic record objects don't implement IComparable.

User userFromDB = User.SingleOrDefault(x => x.UserName == "CmdrTallen");
User modifiedUser = new User();
TryUpdateModel(modifiedUser);
if(CompareOjbects<User>(userFromDB, modifiedUser) != 0)
{
    this.log("User was modified")
    //+ Add modified columns collection to log here
}

Am I re-inventing the wheel? Perhaps a easier way?

+1  A: 

By default the AR template overrides Equals() to compare primary keys instead of base Object comparison. You can change this by changing the ActiveRecord.tt file.

Rob Conery
+2  A: 

What I ended up doing is using this Generic Serializer to take both DB stored record (userFromDB) and modified user (modifiedUser). Serializing them to XML and then using this to create a diffgram. Exactly what I needed.

woot!

CmdrTallen