esmith wrote:
I'm sure this is a common feature to do, and I want to make sure my development team is using LLBLGen in the way in which it was intended to be used.
...
Eric,
I've only been using LLBLGen a short period of time, but I've come to prefer the predicate objects even if they are more typing in simple cases. If you need to build up similar predicates for different database fields or form fields, you can easily parameterise your code and factor it in to helper functions or classes:
void AddFilterTextBox(IPredicateExpression filter, Control filterBox, CheckBox requireExact, TbUserFieldIndex field)
{
if (filterBox.Text.Trim() != String.Empty)
{
if (requireExact.Checked)
{
filter.AddWithAnd(PredicateFactory.CompareValue(field,
ComparisonOperator.Equal, filterBox.Text.Trim()));
}
else
{
filter.AddWithAnd(PredicateFactory.Like(field,
"%" + filterBox.Text.Trim() + "%")));
}
}
}
You then just need one line for each search field:
AddFilterTextBox(filter, RepFirstNameBox, RepFirstNameExact, TbUserFieldIndex.TbusFirstName);
AddFilterTextBox(filter, FieldTwoBox, FieldTwoExact, TbUserFieldIndex.TbusFieldTwo);
AddFilterTextBox(filter, FieldThreeBox, FieldThreeExact, TbUserFieldIndex.TbusFieldThree);
Also, you don't need to use filter.Add(...) first. Using filter.AddWithAnd(...) should work even when there is nothing added previously. (filter.Add(...) also defaults to AddWithAnd(...) if there is already something in the expression)
Regards,
Ben