ArcGIS Pro 2.7 API Reference Guide
CreateFeatureLayer(CIMDataConnection,ILayerContainerEdit,LayerPosition,String,RendererDefinition) Method
Example 

ArcGIS.Desktop.Mapping Namespace > LayerFactory Class > CreateFeatureLayer Method : CreateFeatureLayer(CIMDataConnection,ILayerContainerEdit,LayerPosition,String,RendererDefinition) Method
A CIMDataConnection
A map or group layer instance to which the Feature Layer will be added
LayerPosition specifies whether the Feature Layer should be auto positioned or be on the top or at the bottom
(optional) When it is not provided, the default display name gets used e.g. the dataset name or alias. (default value = "")
(optional) Provide a RendererDefinition to create a FeatureLayer with your custom renderer instead of the default renderer that gets generated automatically. (default value = null)
Overloaded. Create a new Feature Layer instance using a CIMDataConnection and adds that to a container such as a map or group layer. Optionally you can provide a name and rendererDefinition to override the default display name and renderer respectively. This method must be called on the MCT. Use QueuedTask.Run
Syntax

Parameters

dataConnection
A CIMDataConnection
mapOrGroupLayer
A map or group layer instance to which the Feature Layer will be added
position
LayerPosition specifies whether the Feature Layer should be auto positioned or be on the top or at the bottom
layerName
(optional) When it is not provided, the default display name gets used e.g. the dataset name or alias. (default value = "")
rendererDefinition
(optional) Provide a RendererDefinition to create a FeatureLayer with your custom renderer instead of the default renderer that gets generated automatically. (default value = null)

Return Value

Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Example
Create a query layer.
await QueuedTask.Run(() =>
{
  Map map = MapView.Active.Map;
  Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(@"C:\Connections\mySDE.sde")));
  CIMSqlQueryDataConnection sqldc = new CIMSqlQueryDataConnection()
  {
    WorkspaceConnectionString = geodatabase.GetConnectionString(),
    GeometryType = esriGeometryType.esriGeometryPolygon,
    OIDFields = "OBJECTID",
    Srid = "102008",
    SqlQuery = "select * from MySDE.dbo.STATES",
    Dataset = "States"
  };
  FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(sqldc, map, layerName: "States");
});
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

LayerFactory Class
LayerFactory Members
Overload List