Example by CrmSdk
public Guid GetDynamicEntityPrimaryAttributeGuid(DynamicEntity entity)
{
if (entity != null)
{
string strPrimaryKeyAttributeName = entity.Name.ToLower() + "id";
return ((Microsoft.Crm.Sdk.Key)entity.Properties[strPrimaryKeyAttributeName]).Value;
}
return Guid.Empty;
}
Example by Web Service
public Guid GetDynamicEntityPrimaryAttributeGuid(DynamicEntity entity)
{
if (entity != null)
{
string strPrimaryKeyAttributeName = entity.Name.ToLower() + "id";
for (int i = 0; i < entity.Properties.Length; i++)
{
if (entity.Properties[i].Name.ToLower() == strPrimaryKeyAttributeName)
{
KeyProperty property = (KeyProperty)entity.Properties[i];
return property.Value.Value;
}
}
}
return Guid.Empty;
}