subsonic / SubSonic-2.0

SubSonic 2.0 Home
http://subsonic.github.io/
Other
80 stars 45 forks source link

TableColumnSettings PrimaryKey DataType Changed After Save() #4

Closed zhunter closed 12 years ago

zhunter commented 14 years ago

I've been trying to add a function to compare my object TableColumnSettings. When I load 2 objects using the FetchByID they match, when I change one object by editing/saving a column always get the changed column and the primary key to fail the Equals() check. I noticed the datatype on my primary key changed from Int16 to Int32 after calling Save(). I see that the SqlDataProvider.cs, ExecuteQuery(QueryCommand qry) returns a int and ActiveRecord.cs Save() calls SetPrimaryKey(pkVal) that passes on the Int32 to the current object which is causing it to go from a Int16 to a Int32, and thus fail the Equals() check. Easy fix is to reload and compare, but I wanted to share what I found after pulling out a handful of hair.

zhunter commented 14 years ago

To fix my problem, I added the following line before SetPrimaryKey(pkVal) in ActiveRecord.cs.

pkVal = Convert.ChangeType(pkVal, BaseSchema.PrimaryKey.GetPropertyType());

Now my object.Equals() call works perfectly and my CompareTo() function correctly returns only the columns that have values different between the two objects.

6pac commented 12 years ago

This has been merged into the trunk. Thanks.