IEdmEntityType entityType = // get the entity type IEdmStructuralProperty primaryKey = entityType.FindProperty("Id") as IEdmStructuralProperty; // get the primary key property IEdmEntityTypeKey primaryKeyDef = new EdmEntityTypeKey(new[] { primaryKey }); // define the primary key entityType.AddKeys(primaryKeyDef); // add the primary key to the entity type
IEdmEntityType entityType = // get the entity type IEnumerablekeyProperties = entityType.DeclaredKey; // get the key properties of the entity type
IEdmEntityType entityType = // get the entity type IEdmEntity entity1 = // get the first entity IEdmEntity entity2 = // get the second entity IEdmEntityType keyType = entityType.Key.EntityType(); // get the key type of the entity type object keyValue1 = entity1.GetKeyValue(keyType); // get the key value of the first entity object keyValue2 = entity2.GetKeyValue(keyType); // get the key value of the second entity bool isEqual = keyValue1.Equals(keyValue2); // compare the key valuesThis example demonstrates how to compare the key values of two entities of the same entity type using GetKeyValue() method. The package library for this code could be Microsoft.OData.Edm.