Created
August 25, 2012 04:29
-
-
Save xerxesb/3460733 to your computer and use it in GitHub Desktop.
Look, ma! I found in-memory predicate filtering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
*/ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:)