Howdy,
I've got a search function that searches through contacts finding if the input string is in either the firstname OR lastname fields... but I don't quite know how to go about this using the generated code.
This is what I have so far:
public static EntityCollection GetContactCollectionFromString(string strSearch)
{
EntityCollection toReturn = new EntityCollection(new ContactEntityFactory());
char[] delimiter = ", ".ToCharArray();
String[] strSearchParts = strSearch.Split(delimiter);
IPredicateExpression filter = new PredicateExpression();
for (int i = 0; i < strSearchParts.Length; i++)
{
filter.Add(PredicateFactory.Like(DALProg.ContactFieldIndex.LastName, "%" + strSearchParts[i].Trim() + "%"));
filter.Add(PredicateFactory.Like(DALProg.ContactFieldIndex.FirstName, "%" + strSearchParts[i].Trim() + "%"));
}
IRelationPredicateBucket filterbucket = new RelationPredicateBucket();
filterbucket.PredicateExpression.Add(filter);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(toReturn, filterbucket);
}
return toReturn;
}
But that code means that the search string must be found in both firstname and lastname.
Is there any way I can do it so that it is found in the firstnam OR lastname?
If not, is there a way I can merge two collections?