Filter based on master and detail how to?
I want a Linq query like this:
var q = from order in Order
joi开发者_高级运维n detail in Detail on order.OrderId equals detail.OrderId
That permits me to do the following optional filtering, based on user choice :
if (cbxCustomer.Text != string.Empty)
{
q = q.Where(x=>x.CustomerId = (int)cbxCustomer.SelectedItem) // filter based on master
}
if (cbxItem.Text != string.Empty)
{
q = q.Where(x=>x.ItemId = (int)cbxItem.SelectedItem) // filter based on detail
}
the result should be a list of orders with no duplicates that answers the above optional filter.
Thanks
After applying the filter, you need to select just Orders and than use Distinct LINQ extension method.
精彩评论