Skip to content

Instantly share code, notes, and snippets.

@xerxesb
Created August 25, 2012 04:29
Show Gist options
  • Save xerxesb/3460733 to your computer and use it in GitHub Desktop.
Save xerxesb/3460733 to your computer and use it in GitHub Desktop.
Look, ma! I found in-memory predicate filtering.
public IEntityCollection2 FilterEntities(IEntityCollection2 collection, IRelationPredicateBucket filterBucket)
{
collection.DefaultView.Filter = filterBucket.PredicateExpression; // only works for basic filter expressions
return collection.DefaultView.ToEntityCollection();
/*
// say goodbye to all this shitty code.
var result = CreateEntityCollection(EntityType(collection));
var filterField = "";
object filterValue = null;
if (filterBucket.PredicateExpression[0].Contents is PredicateExpression)
{
filterField = ((FieldCompareValuePredicate)((PredicateExpression)filterBucket.PredicateExpression[0].Contents)[0].Contents).FieldCore.Alias;
filterValue = ((FieldCompareValuePredicate)((PredicateExpression)filterBucket.PredicateExpression[0].Contents)[0].Contents).Value;
}
else
{
filterField = ((FieldCompareRangePredicate)filterBucket.PredicateExpression[0].Contents).FieldCore.Alias;
filterValue = ((FieldCompareRangePredicate)filterBucket.PredicateExpression[0].Contents).Values[0];
}
foreach (IEntity2 entity in collection)
{
if (entity.Fields[filterField].CurrentValue.Equals(filterValue))
{
result.Add(entity);
}
}
return result;
*/ }
@dahvyd
Copy link

dahvyd commented Aug 30, 2012

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment