I'm trying to use the Predicate from Albahari to create a TSQL statement like:
select * from channel
where channel.VendorID IN (@vendorIDs)
AND channel.FranchiseID IN (@franchiseIDs)
or a predicate like : c => (c.VendorID = x || c.VendorID == x2 ...) && (c.FranchiseID == f || c.FranchiseID == f2 ...)
but I'm having troubles. Here is my attempt:
var vendorPredicate = PredicateBuilder.False<Channel>();
foreach (Vendor vendor in workOrderSessionData.SelectedVendors)
{
int tempId = vendor.VendorID;
vendorPredicate = vendorPredicate.Or(c => c.VendorID == tempId);
}
var franchisePredicate = PredicateBuilder.False<Channel>();
foreach (Franchise franchise in workOrderSessionData.SelectedFranchises)
{
int tempId = franchise.FranchiseID;
franchisePredicate = franchisePredicate.Or(c => c.FranchiseID == tempId);
// doesn't work franchisePredicate.Or(vendorPredicate);
}
Channel.SelectByPredicate(franchisePredicate);
My table has 60,000 rows, so going to the database and selecting them all, then filtering is not an option. Channel is a LinqToSql entity. Also either the SelectedFranchises or the SelectedVendors can be empty, but not both at one time. EDIT: I need to distinct this list by the channel.Franchise.Name as well.. Maybe I should just use a stored procedure?
How would you do this?