ThinkGeo.com    |     Documentation    |     Premium Support

Read values I just added in layer wihtin aTransaction

Hello,


I'm adding geometries in an InMemoryLayer using Transactions.


After adding an object, using layer.EditTools.Add(feature), I cannot read this object with the QueryTools without commiting the transaction first.


I can understand that another transaction cannot read this objcet (as in SQL Transactions), but in the same transaction I'm not able to read my objects back. Is it normal ?


Thanks,


Guillaume.



Guillaume, 



There is a property in EditTools called IsTransactionLive, if it is set to true, the added feature will also be queries before commit. Here is a sample: 


            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();

            Feature feature = new Feature(1, 1, "id");
            inMemoryFeatureLayer.Open();
            inMemoryFeatureLayer.EditTools.BeginTransaction();
            inMemoryFeatureLayer.EditTools.IsTransactionLive = true;
            inMemoryFeatureLayer.EditTools.Add(feature);

            // return the feature we just added
            Feature newFeature = inMemoryFeatureLayer.QueryTools.GetFeatureById("id", ReturningColumnsType.NoColumns);


Sure you can directly use the InternalFeatures also. 

 
            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();

            inMemoryFeatureLayer.InternalFeatures.Add("key2", new Feature(1, 1, "key1"));
            inMemoryFeatureLayer.BuildIndex();

            // feature2.Id equals to "key1"
            Feature feature2 =  inMemoryFeatureLayer.InternalFeatures["key2"];



Thanks, 



Ben 


Thank you Ben !

You are welcome. Any other questions, let us know.