Select to view content in your preferred language

Unstable Row.Handle

05-25-2020 02:46 AM
Esri Contributor

The Row.Handle property is not stable but it should according to the docs:

Other handles are. Table.Handle for instance. Am I doing something wrong? Help is much appreciated, thanks.

The code snippet below is a unit test. The Row.Handle is not stable in Pro App context either, e.g. running in QueuedTask.

public void Compare_row_handles_SDE_LearningTest()
	var osaConnection = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
		Instance = "bla",
		AuthenticationMode = AuthenticationMode.OSA

	using (var geodatabase = new Geodatabase(osaConnection))
		var featureClass = geodatabase.OpenDataset<FeatureClass>("foo");
		var row0 = GetRow(featureClass, 2453);
		var row1 = GetRow(featureClass, 2453);

		Console.WriteLine("rows are equal: {0}", Equals(row0, row1));
		Console.WriteLine("rows are reference equals: {0}", ReferenceEquals(row0, row1));
		Console.WriteLine("row handles are equal: {0}", Equals(row0.Handle, row1.Handle));

		Assert.AreNotEqual(row0.Handle, row1.Handle);

public static Row GetRow(Table table, long oid)
	using (var cursor = table.Search(new QueryFilter
		WhereClause = $"{table.GetDefinition().GetObjectIDField()} = {oid}"
	}, false))
		if (! cursor.MoveNext())
			return null;

		var row = cursor.Current;
		Assert.False(cursor.MoveNext(), "more than one row found");

		return row;
0 Kudos
1 Reply
Esri Regular Contributor

You're correct.  `Row.Handle` is not stable.  

Under the hood, the Handle property is just a pointer to an underlying ArcObjects object.  When you open the same table twice, ArcObjects reuses the same COM objects, so Table.Handle is identical for both Table objects.

With rows, this isn't true.  Fetching the same two database rows with two cursors will create two different row objects (and different Row.Handle values).  Flipping it around, if you use a recycling cursor, all of the rows fetched from that cursor will use the same underlying object, and Row.Handle will be the same for every one.

(Since I've seen your other post, I'll also add that Table.Handle will have a different value every time you start ArcGIS Pro.)

I hope this helps,


0 Kudos