GlobalId与普通的字段转换


// Converts a GlobalID field to a GUID field.
public static void ConvertGlobalIdToGuid(IWorkspace workspace, String
  datasetName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GlobalID field.
  IClassEx classEx = (IClassEx)table;
  if (!classEx.HasGlobalID)
  {
    throw new Exception(String.Format("No GlobalID column in table: {0}.",
      datasetName));
  }
  String globalIDFieldName = classEx.GlobalIDFieldName;

  // Convert the GlobalID column to a GUID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.UnregisterGlobalIDColumn(globalIDFieldName);
}

2 一下代码实现将普通的字段转变成GlobalID

/ Converts a GUID field to a GlobalID field.
public static void ConvertGuidToGlobalId(IWorkspace workspace, String
  datasetName, String guidFieldName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GUID field to convert.
  IFields fields = table.Fields;
  int guidFieldIndex = fields.FindField(guidFieldName);
  IField guidField = fields.get_Field(guidFieldIndex);
  if (guidField.Type != esriFieldType.esriFieldTypeGUID)
  {
    throw new Exception(String.Format("Field {0} is not a GUID field.",
      guidFieldName));
  }

  // Convert the GUID column to a GlobalID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.RegisterGlobalIDColumn(guidField.Name);
}


转载自:https://blog.csdn.net/pfjgeng/article/details/8241856

You may also like...