.net SDK - Adding/Creating a feature... default values?

587
1
11-09-2016 10:50 AM
brianbullas
New Contributor III

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.

0 Kudos
1 Reply
brianbullas
New Contributor III

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.

0 Kudos