I am trying to figure out how to use a field's default value when using the .net c# SDK when adding a feature.
In ArcGIS, in the Feature Class properties, each field can have a default value:
However, I can't seem to find the Default Value via the SDK. Here is my code:
var table = new ServiceFeatureTable
{
ServiceUri = url,
OutFields = new OutFields(OutFields.All)
};
await GenerateToken(url).ConfigureAwait(false);
await table.InitializeAsync(table.SpatialReference).ConfigureAwait(false);
var schemaFields = table.Schema.Fields.ToList();
var feature = new GeodatabaseFeature(table.Schema)
{
Geometry = geometry
};
foreach (var attribute in attributes)
{
var field = schemaFields.FirstOrDefault(x => x.Name.ToLower().Equals(attribute.Key.ToLower()));
if (field != null)
{
feature.Attributes[attribute.Key] = attribute.Value != null ? TranslateField(field, attribute.Value) : null;
}
}
await table.AddAsync(feature);
var result = await table.ApplyEditsAsync(true);
nowhere in the schema field or the feature class is there an option to apply a default value.
I think i figured it out....
in
var table = new ServiceFeatureTable
{
ServiceUri = url,
OutFields = new OutFields(OutFields.All)
};
I am setting out fields to all. If i instead only ask for a couple selected out fields, then the unselected (ones not included in the outfields list) fields will use their default value, if there is one.
SO:
var table = new ServiceFeatureTable
{
ServiceUri = url,
OutFields = new OutFields(attributes.Select(x=>x.Key)),
};
will use default values when inserting / creating if it's not included in the list of attributes above.