Use transactions to manage how changes are committed to a geodatabase.
Use case
Transactions allow you to control how changes are added to a database. This is useful to ensure that when multiple changes are made to a database, they all succeed or fail at once. For example, you could have a business rule that both parent/guardian and student must be added to a database used for calculating school bus routes. You can use transactions to avoid breaking the business rule if you lose power while between the steps of adding the student and parent/guardian.
How to use the sample
When the sample loads, a feature service is taken offline as a geodatabase. When the geodatabase is ready, you can add multiple types of features. To apply edits directly, uncheck the 'Require a transaction for edits' checkbox. When using transactions, use the buttons to start editing and stop editing. When you stop editing, you can choose to commit the changes or roll them back. At any point, you can synchronize the local geodatabase with the feature service.
How it works
- Take the feature service offline as a geodatabase and display the local tables from the geodatabase in feature layers.
- If the checkbox is checked, begin the transaction on the geodatabase.
- Add one or more features.
- When ready, either commit the transaction to the geodatabase or roll back the transaction.
- Use a geodatabase sync task to sync changes to the local geodatabase with the feature service.
Relevant API
- Geodatabase
- Geodatabase.BeginTransaction
- Geodatabase.CommitTransaction
- Geodatabase.IsInTransaction
- Geodatabase.RollbackTransaction
About the data
The sample uses a publicly-editable, sync-enabled feature service demonstrating a schema for recording wildlife sightings.
Tags
commit, database, geodatabase, transact, transactions
Sample Code
<UserControl x:Class="ArcGISRuntime.WPF.Samples.GeodatabaseTransactions.GeodatabaseTransactions"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
<UserControl.Resources>
<Style TargetType="Button">
<Setter Property="Padding" Value="5,5,5,5" />
<Setter Property="Margin" Value="5,0,0,5" />
</Style>
</UserControl.Resources>
<Grid>
<esri:MapView x:Name="MyMapView" />
<Border Style="{StaticResource BorderStyle}">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="StartEditingButton"
Grid.Column="0"
Margin="0,0,0,5"
Click="BeginTransaction"
Content="Start Editing"
IsEnabled="False" />
<Button x:Name="StopEditingButton"
Grid.Column="1"
Click="StopEditTransaction"
Content="Stop Editing"
IsEnabled="False" />
<Button x:Name="SyncEditsButton"
Grid.Column="2"
Click="SynchronizeEdits"
Content="Synchronize"
IsEnabled="True" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="AddBirdButton"
Grid.Column="0"
Margin="0,0,0,5"
Click="AddNewFeature"
Content="Add Bird Feature"
IsEnabled="False" />
<Button x:Name="AddMarineButton"
Grid.Column="1"
Click="AddNewFeature"
Content="Add Marine Feature"
IsEnabled="False" />
</Grid>
<CheckBox x:Name="RequireTransactionCheckBox"
Click="RequireTransactionChanged"
Content="Require a transaction for edits"
IsChecked="True" />
<ProgressBar x:Name="LoadingProgressBar"
Height="15"
Margin="0,5,0,5"
IsIndeterminate="True" />
<TextBlock x:Name="MessageTextBlock"
Foreground="Blue"
Text="Generating local geodatabase ..."
TextWrapping="Wrap" />
</StackPanel>
</Border>
</Grid>
</UserControl>