Otis wrote:
Using an int, makes the enums not going to work. The enums work because they're typed and the compiler knows which method to call. If you pass in an int, it doesn't know that.
So if your routine is for a given entity, pass in the field index as an enum. If you don't know that, but you do know the entity type (enum value), you can pass in that too (as EntityType), then create an EntityFields object using the EntityFieldsFactory.CreateEntityFieldsObject(entityType).
You then index in that object with fieldIndex to get the field object, and simply use the FieldLikePredicate constructor instead of the PredicateFactory class.
Oy. I am still having a hard time with this.
(I am now using Adapter--not sure if that makes any difference.)
In both sections of code (the calling section and the function), I listed a commented way I would like it to work (so that a change in field names would cause compiler errors). But I can't get it to work the UNcommented way either.
predTemp = CreateStringPredicate(searchParam.ClientName, "ClientName", SecurityDAL.EntityType.ClientEntity);
//predTemp = CreateStringPredicate(searchParam.ClientName, SecurityDAL.ClientFieldIndex.ClientName, SecurityDAL.EntityType.ClientEntity);
//protected IPredicateExpression CreateStringPredicate(ArrayList stringArray, System.Enum fieldIndex,
// SecurityDAL.EntityType entityType)
protected IPredicateExpression CreateStringPredicate(ArrayList stringArray, string fieldName, SecurityDAL.EntityType entityType)
{
IPredicateExpression pred = new PredicateExpression();
int x;
//this part works
IEntityFields2 eFields = SecurityFactory.EntityFieldsFactory.CreateEntityFieldsObject(entityType);
//IEntityField2 fieldeFields[(int)fieldIndex];
IEntityField2 field = eFields[fieldName];
for (x = 0 ; x < stringArray.Count ; x++)
{
//the following line of code gives the error:
//Argument '1': cannot convert from 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2'
//to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'
pred.AddWithOr(new FieldLikePredicate(field, "%" + stringArray[x] + "%"));
}
return pred;
}
As always, thanks for any help.
Phil