This could be a way to do that:
public List<IEntityRelation> GetRelationsFromField(IEntityCore entity, IEntityFieldCore field)
{
var relsFound = new List<IEntityRelation>();
var relations = entity.GetAllRelations();
foreach (var rel in relations)
{
var fieldsFromPk = rel.GetAllPKEntityFieldCoreObjects();
var fieldsFromFk = rel.GetAllFKEntityFieldCoreObjects();
bool existOnRel = fieldsFromPk.Any(f => f.ContainingObjectName == field.ContainingObjectName && f.Name == field.Name);
existOnRel |= fieldsFromFk.Any(f => f.ContainingObjectName == field.ContainingObjectName && f.Name == field.Name);
if (existOnRel)
{
relsFound.Add(rel);
}
}
return relsFound;
}
...and the usage:
var relsFound = GetRelationsFromField(new CustomerEntity(), CustomerFields.CustomerId);