MapDotNet UX Help

The MapDotNet UX edit model is used for feature editing.  The edit model uses classes in ISC.MapDotNetServer.Common and ISC.MapDotNetServer.Common.Data.  Note that the contents of these namespaces are slightly different under Silverlight.  These differences will be discussed where applicable.

The Edit Request

The edit model is used to edit data in map layers.  (Requests can also be constructed to edit data tables that are not represented by map layers but this is a less common scenario.)  The EditRequest class is used to encapsulate row edits.  An EditRequest is serialized and passed to an instance of the feature update service, FeatureUpdateService.svc.  In the RIM controls, the Services class can be used to create a client proxy for the feature update service.  Otherwise, you can create one from a service reference.

The EditRequest class has the following properties:

  • DataSourceSpecification - this can refer to either a ConnectionDataSourceSpecification or a MapLayerDataSourceSpecification.  The MapLayerDataSourceSpecification is more commonly used.  A MapLayerDataSourceSpecification has the following properties:
    • MapID, LayerID - together, these refer to the map layer to edit.  Connection information will be obtained for that layer on the server.
    • WhereClauseOverride - this is not used for edit requests.

    Use a ConnectionDataSourceSpecification only if you know the complete connection information.  This can be used to edit data tables that are not associated with maps.  Note that although Layer.ConnectionSpecification is a ConnectionDataSourceSpecification, in client code a layer's ConnectionSpecification is unusable because the connection string is stripped from it.
  • RowErrorBehavior - this is used to indicate whether to continue (default) or roll back all changes when there is an error on an individual row action during an edit.  Note that the connector for ArcSDE does not support rollbacks.
  • DataCoordSys - this indicates the coordinate reference system that shapes being inserted or updated are in.  This need only be set when the new data is in a different coordinate reference system from that of that data source being edited.  This should usually be a ProjCoordSys object, but if you are editing ArcSDE and using the data source to do transformations, use a WKTCoordSys object.
  • UseDataSourceToTransform - indicates whether to use the data source rather than MapDotNet to do coordinate system transformation.  Default is false.  Note that Sql Server 2008 cannot transform data.
  • Data - this is not an ADO.Net DataTable as in the 6.x series, but instead an instance of ISC.MapDotNetServer.Common.Data.EditDataModel.DataTable.  This contains DataRow and DataColumn objects used to define the row edits that are to be performed.

The Edit Data Model

In the 6.x series, the edit model used an ADO.Net DataTable to pass data to be edited, with RowState indicating the action to perform.  To support editing under Silverlight in UX, it was necessary to revise this model.  The ISC.MapDotNetServer.Common.Data.EditDataModel namespace contains DataTable, DataColumn, DataRow, and DataRowState members that are very similar to their ADO.Net counterparts.  They support a subset of the methods of their counterparts, implementing the methods and properties most commonly used in client code in our earlier edit model.  However, our DataTable implementation differs from an ADO.Net DataTable in the following significant ways.

  • PrimaryKey property - in ADO.Net, this is an array of DataColumns.  In our model, it is a single DataColumn.
  • ExtendedProperties property - this is not present in our data model.  In 6.x, we added an "Error" property to this collection for global errors.  In UX, we instead have a TableError property.
  • TableError property - not present in ADO.Net.  In our model, used to hold a message about a global error that prevented all editing.
  • HasRowErrors property and GetErrorRows method - these replace the HasErrors property and GetErrors method of the ADO.Net DataTable.

The DataTable is used both to pass data to the server and to return results to the client.  Create the Data for an EditRequest in the following way.

  1. Create a DataTable and give it an appropriate TableName.
  2. Add DataColumns to the table's Columns collection.  The geometry column should be assigned the string Type [typeof(string)]. 
    Assign a column as the PrimaryKey if needed.
    • If you are going to update or delete data, you must assign a primary key column.  The value of this column in each row will be used for the lookup.
    • If you are going to insert data, you may assign a primary key column.  If so, this column should reference a database column that contains an auto-generated numeric key, such as an ArcSDE OBJECTID or a SQL Server 2008/2012 IDENTITY column.  New key values will be returned to the client.
  3. Use the NewRow method of the DataTable to get a dataRow with the table's schema.
  4. Populate the row with appropriate column values.  To populate a geometry column, serialize the shape and assign the string to the column.
  5. Add the row to the table's Rows collection.
  6. At this point the row's RowState is "Added".  This marks it as an insert row.  To mark it as an update or a delete row, you can either assign the RowState directly or do one of the following:
    • To make it a delete row, call the row's Delete() method.
    • To make it an update row, call the row's AcceptChanges() method and then set a column value.
  7. Repeat steps 3 through 6 as needed.

The following code sample demonstrates the creation of an EditRequest with a single row of data to insert.

      EditRequest ereq = new EditRequest();
     ereq.DataSourceSpecification = new MapLayerDataSourceSpecification("mapID", "layerID");
     ereq.Data = new DataTable();
     ereq.Data.TableName = "layerID";
     // columns
     ereq.Data.PrimaryKey = ereq.Data.Columns.Add("id", typeof(int));
     ereq.Data.Columns.Add("shape", typeof(string));
     ereq.Data.Columns.Add("label", typeof(string));
     // data                           
     DataRow trow = ereq.Data.NewRow();
     trow["shape"] = new ISC.MapDotNetServer.Common.Point(-90.0, 36.0).Serialize();
     trow["label"] = "point 1";

The Response to an Edit Request

Unlike the map or query models, the edit model does not have an EditResponse class corresponding to its EditRequest class. What is returned from the service call is a serialized DataTable. The TableError property will be set if an error prevented the edits from being executed. Otherwise, there will be a DataRow in the response for every row in the request. However, the only column present will be the primary key column, if there was one. RowState will be unchanged and RowError may be set.

You can check HasRowErrors on the DataTable to see if there are rows with errors and call GetErrorRows to get all rows with errors.

If the edit table had a primary key column defined and there were insert rows, the returned table will hold the new primary key values for newly inserted rows.

Feature Update Service Method

string Edit(string editRequest);

This is the only method of the feature update service. It takes a serialized EditRequest and returns a serialized EditDataModel.DataTable. The Edit may not be canceled once it is started.