I have copied complete method here. In last 10 lines, I am trying to add filter to the query and also find count. I am struggling in this part. Your help will be appreciated.
var target = new Personnel();
const long incidentId = 1;
IList actual = target.Find(incidentId);
var list = ((IEntity2)actual[0]).GetAllRelations();
string str = string.Empty;
using (var adapter = new DataAccessAdapter())
{
var metaData = new LinqMetaData(adapter);
foreach (IEntityRelation entityRelation in list)
{
IEntityFieldCore fc = entityRelation.GetFKEntityFieldCore(0);
IEntityFieldCore fc1 = entityRelation.GetFKEntityFieldCore(1);
string en = fc.ContainingObjectName;
string en1 = fc1.ContainingObjectName;
EntityType typeOfEntity = (EntityType)Enum.Parse(typeof(EntityType), en);
EntityType typeOfEntity1 = (EntityType)Enum.Parse(typeof(EntityType), en1);
IEntity2 entityInstance = AmbuPro.DAL.FactoryClasses.GeneralEntityFactory.Create(typeOfEntity);
IEntityCollection2 ec = entityInstance.GetEntityFactory().CreateEntityCollection();
IPredicateExpression bucket = new PredicateExpression();
bucket.Add(new FieldCompareValuePredicate((IEntityField2)fc, ComparisonOperator.Equal, 1));
bucket.Add(new FieldCompareValuePredicate((IEntityField2)fc1, ComparisonOperator.Equal, 1));
IRelationCollection rs = new RelationCollection();
rs.Add(entityRelation);
long c = Convert.ToInt64(ec.Count);
if (entityRelation.TypeOfRelation == RelationType.OneToMany &&
entityRelation.TypeOfRelation == RelationType.OneToOne)
str += " " + entityRelation.MappedFieldName;
}
}