QueuedTask.Run(() =>
{
//To create a KG layer (on a map or link chart) with a subset of
//entities and relates, you must create an "id set". The workflow
//is very similar to how you would create a SelectionSet.
//First, create a dictionary containing the names of the types to be
//added plus a corresponding list of ids (just like with a selection set).
//Note: null or an empty list means add all records for "that" type..
var kg_datamodel = kg.GetDataModel();
//Arbitrarily get the name of the first entity and relate type
var first_entity = kg_datamodel.GetEntityTypes().Keys.First();
var first_relate = kg_datamodel.GetRelationshipTypes().Keys.First();
//Make entries in the dictionary for each
var dict = new Dictionary<string, List<long>>();
dict.Add(first_entity, new List<long>());//Empty list means all records
dict.Add(first_relate, null);//null list means all records
//or specific records - however the ids are obtained
//dict.Add(entity_or_relate_name, new List<long>() { 1, 5, 18, 36, 78});
//Create the id set...
var idSet = KnowledgeGraphLayerIDSet.FromDictionary(kg, dict);
//Create the layer params and assign the id set
var kg_params = new KnowledgeGraphLayerCreationParams(kg)
{
Name = "KG_With_ID_Set",
IsVisible = false,
IDSet = idSet
};
//Call layer factory with map or group layer container
//A KG layer containing just the feature layer(s) and/or standalone table(s)
//for the entity and/or relate types + associated records will be created
var kg_layer = LayerFactory.Instance.CreateLayer<KnowledgeGraphLayer>(
kg_params, map);
});