public void MainMethodCode() { using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb")))) using (FeatureClass featureClass = fileGeodatabase.OpenDataset <FeatureClass>("PollingPlace")) { QueryFilter queryFilter = new QueryFilter { WhereClause = "CITY = 'Plainfield'" }; Selection selection = featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal); // The result is a mapping between those object ids which failed validation and the reason why the validation failed (a string message). IReadOnlyDictionary <long, string> validationResult = featureClass.Validate(selection); RowCursor rowCursor = featureClass.Search(queryFilter, false); List <Feature> features = new List <Feature>(); try { while (rowCursor.MoveNext()) { features.Add(rowCursor.Current as Feature); } // This is equivalent to the validation performed using the selection. IReadOnlyDictionary <long, string> equivalentValidationResult = featureClass.Validate(features); // Again this is equivalent to both the above results. IReadOnlyDictionary <long, string> anotherEquivalentResult = featureClass.Validate(queryFilter); SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter { FilterGeometry = new EnvelopeBuilder( new MapPointBuilder(1052803, 1812751).ToGeometry(), new MapPointBuilder(1034600, 1821320).ToGeometry()).ToGeometry(), SpatialRelationship = SpatialRelationship.Within }; IReadOnlyDictionary <long, string> spatialFilterBasedValidationResult = featureClass.Validate(spatialQueryFilter); } finally { rowCursor.Dispose(); Dispose(features); } } // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { QueryFilter parkFilter = new QueryFilter { WhereClause = "FCODE = 'Park'" }; Selection parkSelection = enterpriseFeatureClass.Select(parkFilter, SelectionType.ObjectID, SelectionOption.Normal); // Remember that validation cost is directly proprtional to the number of Features validated. So, select the set of features to be // validated judiciously. This will be empty because all the Park Features are valid. IReadOnlyDictionary <long, string> emptyDictionary = enterpriseFeatureClass.Validate(parkSelection); // We are adding an invalid feature to illustrate a case where the validation result is not empty. long invalidFeatureObjectID = -1; EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { RowBuffer rowBuffer = null; Feature feature = null; try { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); rowBuffer = enterpriseFeatureClass.CreateRowBuffer(); rowBuffer["FACILITYID"] = "FAC-400"; rowBuffer["NAME"] = "Griffith Park"; rowBuffer["OWNTYPE"] = "Municipal"; rowBuffer["FCODE"] = "Park"; // Note that this is an invalid subtype value. rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 890; rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilder(new List <Coordinate2D> { new Coordinate2D(1021570, 1880583), new Coordinate2D(1028730, 1880994), new Coordinate2D(1029718, 1875644), new Coordinate2D(1021405, 1875397) }).ToGeometry(); feature = enterpriseFeatureClass.CreateRow(rowBuffer); invalidFeatureObjectID = feature.GetObjectID(); } catch (GeodatabaseException exObj) { Console.WriteLine(exObj); } finally { if (rowBuffer != null) { rowBuffer.Dispose(); } if (feature != null) { feature.Dispose(); } } }, enterpriseFeatureClass); editOperation.Execute(); // This will have one keypair value for the invalid row that was added. IReadOnlyDictionary <long, string> result = enterpriseFeatureClass.Validate(parkFilter); // This will say "invalid subtype code". string errorMessage = result[invalidFeatureObjectID]; } }