Hi experts,
I'm trying to write a rather abstract lookup method with the following signature
INPUT:
- an EntityCollection and
- a PredicateExpression
OUTPUT:
- PK of the found entity
So, the method head would like this:
private long LookUpEntityIDByFilterExpression(IEntityCollection searchTable, PredicateExpression searchExpression)
Unfortunately I do not know how to compute the EntityType to a given EntityCollection, so right now my function looks like this:
private long LookUpEntityIDByFilterExpression(IEntityCollection searchTable, IEntity searchEntity, PredicateExpression searchExpression)
{
long result = 0;
try
{
searchTable.GetMulti(searchExpression);
if (searchTable.Count > 0)
{
foreach (IEntityField fld in searchEntity.Fields)
{
if (fld.IsPrimaryKey)
result = Convert.ToInt64(searchTable[0].Fields[fld.Name].CurrentValue);
}
}
}
catch (Exception e)
{
}
//Return result
return result;
}
Does anybody know how to do this, so I can make my function calls a little bit more efficient/shorter?