Hi,
my problem is following:
I have two entities: company and contact. A company has several contacts.
Owner, Manager1, Manager2, and so on. The relation is 1:1.
Somewhere in my code I have a contact, without any information to which field it belongs. All I know is that it belongs to a company.
Now I need to determine the contact type.
My idea was to iterate all entity fields which are a contact and check if any of those contain my contact ID. With the field name I'm able to decide what type of contact it is.
This was my first try:
public string DetermineContactType(ContactEntity entity) {
var contactFields = Fields.OfType<IEntityFieldCore>().Where(x => x.DataType == typeof (ContactEntity));
var matchingField = contactFields.FirstOrDefault(x => x.CurrentValue == (object)entity.Id);
if(matchingField == null)
return null;
return matchingField.Name;
}
However, this doesn't work as DataType isn't of type Entity, rather it is an int.
Is there any other way to get the entity type of a field?
Thanks in advance!