subsonic / SubSonic-3.0-Templates

T4 Template Project for the peeps
http://subsonic.github.io/
105 stars 46 forks source link

Bug in ActiveRecord.tt file #35

Open yjagota opened 14 years ago

yjagota commented 14 years ago

At Line 273 of ActiveRecord.tt, Equals method performes the equality using this line: return compare.KeyValue()==this.KeyValue(); where it should be: return compare.<#=tbl.PK.CleanName#>==this.<#=tbl.PK.CleanName#>;

KeyValue() returns an object. Consider the case where Primary key is an int. When a boxed int is returned from KeyValue method, Equals method will return false in every case (even if the primary int key contains the same value) because the == operator checks for referential equality as object is a class (int is a type) and both the objects are sitting at different memory locations in the heap.

The reason I am posting this is because this caused a very irritating error in my WPF ListView. Details here: http://stackoverflow.com/questions/1621239/wpf-listview-gridview-single-selection-bug

epalm commented 13 years ago

This was driving me crazy, I thought something was wrong with my XAML. My ListBox just wouldn't work properly. I finally tracked it down to Equals doing weird things. Thanks for the validation, yjagota.