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.
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.
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