views:

24

answers:

1

I got a problem with a DataTable handling an object defined by myself (Position). The object stores some data and overwrites ToString, Equals and GetHashCode. Further it provides the static operators for == and !=.

The DataTable works fine as long the column storing this object is not a key column. Setting it as a PrimaryKey and merge another table to it fails, because the content will not found equal. (Suppricing the datagridview and the DataTable itself finds the data violating the key after merging.)

Attached you'll find some manual comparison of the data after merging.

Has anybody an idea how to deal with that?

Best regards, Tilo

this.data.Rows[1][5]==this.data.Rows[0][5]
false

(Position)this.data.Rows[1][5]==(Position)this.data.Rows[0][5]
true

this.data.Rows[1][5].Equals(this.data.Rows[0][5])
true

this.data.Rows[1][5].GetHashCode()
-461267399
this.data.Rows[0][5].GetHashCode()
-461267399

this.data.Columns[5]
{PositionX}
base {System.ComponentModel.MarshalByValueComponent}: {PositionX}
AllowDBNull: false
AutoIncrement: false
AutoIncrementSeed: 0
AutoIncrementStep: 1
Caption: "PositionX"
ColumnMapping: Element
ColumnName: "PositionX"
DataType: {Name = "Position" FullName = "TiloW.Parameter.Position"}
DateTimeMode: UnspecifiedLocal
DefaultValue: {}
Expression: ""
ExtendedProperties: Count = 1
MaxLength: -1
Namespace: ""
Ordinal: 5
Prefix: ""
ReadOnly: false
Table: {}
Unique: false 
A: 

Just for information. I found a solution adding a new column storing the overriden hashcode which will be used for merging and internal things. It will be deleted just before export and created during import or generation.

T. Wünsche