[mapguide-users] How to get an auto-generated Id after
InsertFeature ?
Paul Spencer
pagameba at gmail.com
Fri Oct 5 15:41:13 EDT 2007
Hi Julien,
this appears to be a bug in mapguide. I ran into the same problem
and discussed it with the core developers and they agree that the
resulting feature reader does not contain the ids of the inserted
features.
I do not know of a work around at this time. Actually, I just
thought of one. Add an attribute to your sdf file called
'uniqueid'. Create a unique value (uuid perhaps) and use it as the
value of that attribute when you insert the new feature. Then, after
you insert it, you can select it using a filter than selects only
that record. Then you can get the id.
Cheers
Paul
On 3-Oct-07, at 8:09 AM, julienltr wrote:
>
> 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.
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
+-----------------------------------------------------------------+
|Paul Spencer pspencer at dmsolutions.ca |
+-----------------------------------------------------------------+
|Chief Technology Officer |
|DM Solutions Group Inc http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+
More information about the mapguide-users
mailing list