I am desperately trying to use LinqKits PredicateBuilder to allow the user to enter a search term into a text box and return records from two database tables/entitysets but I'm struggling to get anywhere. The (simplified) database structure is as follows:
Person Alias
------ ------
A_ID
P_ID ---------------< P_ID
P_FIRST_NAME A_FIRST_NAME
P_SURNAME A_SURNAME
So, each person can have 0 or many aliases. What I am trying to do is allow the user to search on a name and pull back the rows from the Person table where that name matches that in either the Person or the Alias table. So far I have got:
var peopleQuery = MainFrm.genesisContext.People.AsExpandable();
var peoplePredicate = PredicateBuilder.True<Person>();
var aliasQuery = MainFrm.genesisContext.Alias.AsExpandable();
var aliasPredicate = PredicateBuilder.False<Alias>();
if (!String.IsNullOrEmpty(txtFirstName.Text.Trim()))
{
peoplePredicate = peoplePredicate.And(p => p.P_FIRST_NAME == txtFirstName.Text);
aliasPredicate = aliasPredicate.And(a => a.A_FIRST_NAME == txtFirstName.Text);
peoplePredicate = peoplePredicate .Or(p => aliasPredicate);
}
This doesn't work because I'm trying to convert from People to Alias. Basically I'm completely stuck and not sure whether it is even possible to do an Or query on two different tables(?)