hplloyd wrote:
How can I use a field index in a Predicate expression
I.E. instead of doing this
myExpression.Add(PredicateFactory.CompareValue(UserPreferenceFieldIndex.UserID, ComparisonOperator.Equal, intParentID));
I want to do this
UserPreferenceEntity mEntity = new UserPreferenceEntity();
myExpression.Add(PredicateFactory.CompareValue(mEntity.Fields[3].FieldIndex, ComparisonOperator.Equal, intParentID));
because the field with ID of 3 is the User ID column
This obviously does not work but is there a way - what am I doing wrong?
The PredicateFactory uses the enum types. This means that the actual enum type has to be passed in, you're passing in an integer.
However this is easily circumvented, as the PredicateFactory under the hood creates a FieldCompareValuePredicate instance, which accepts an EntityField. I'm not sure if you're using adapter or selfservicing, but here are the statements you can use:
selfservicing:
UserPreferenceEntity mEntity = new UserPreferenceEntity();
myExpression.Add(new FieldCompareValuePredicate(
mEntity.Fields[3],
ComparisonOperator.Equal,
intParentID));
adapter:
UserPreferenceEntity mEntity = new UserPreferenceEntity();
myExpression.Add(new FieldCompareValuePredicate(
mEntity.Fields[3],
null,
ComparisonOperator.Equal,
intParentID));