[mapguide-users] How to get an auto-generated Id after InsertFeature ?

julienltr julienleture at hotmail.com
Wed Oct 3 08:09:35 EDT 2007


Hi,

I have a SDF file with three attributes :
- Id Int32 Autogenerated
- Name String
- Data Geometry

When a I want to add new value I insert a string for "Name" and a geometry
for "Data".
Id is an integer auto-generated.
My question is how to know which Id was generated?

In the documentation, I find this in MgFeatureService::UpdateFeatures:
"Returns an MgPropertyCollection object. Each property in the collection
corresponds to a command in the MgFeatureCommandCollection argument. The
property name is the index of the command in the feature command collection.
If the command is of type MgInsertFeatures, the property type is an
MgPropertyType::Feature, and its value is a MgFeatureReader object. The
feature reader object contains the set of properties inserted into the
datastore by the insert command."

My problem is that I can't read into this feature reader?
I get an MgNullReferenceException whereas the feature reader isn't null!
But I don't think I can find the id inside this reader...

Here's my code in C# (not to hard to understand ;))
 
// new values (name & data)
MgPropertyCollection propertyValues = new MgPropertyCollection();
propertyValues.Add(new MgStringProperty("Name", DateTime.Now.ToString()));
propertyValues.Add(new MgGeometryProperty("Data", byteReader));

// insert new values
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(new MgInsertFeatures(ClassName, propertyValues));
MgPropertyCollection propertyCollection =
featureService.UpdateFeatures(featureSourceId, commands, false);

// read the result
for (i = 0; i < propertyCollection.Count; i++)
{
	// if MgInsertFeatures, PropertyType == MgPropertyType.Feature
	if (propertyCollection.GetItem(i).PropertyType == MgPropertyType.Feature)
	{
		MgFeatureProperty featureProperty =
(MgFeatureProperty)propertyCollection.GetItem(i);
		MgFeatureReader featureReader = featureProperty.GetValue();
        for (int j = 0; j < featureReader.GetPropertyCount(); j++)
		// GetPropertyCount() throw an MgNullReferenceException
        {
                string propertyName = featureReader.GetPropertyName(j);
				object propertyValue = Tools.GetProperty(featureReader, propertyName);
// own function to do GetString or GetInt32, etc.
		}
	}
}
-- 
View this message in context: http://www.nabble.com/How-to-get-an-auto-generated-Id-after-InsertFeature---tf4561407s16610.html#a13017599
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list