Hi, probably not the best solution but off the top of my head i can think of 2 methods. 1. Use a switch on ProductID - case 0: --> do query to return all default: --> do other query to return specifics matching ProductId 2.
List<< PartModel>> results = **((ProductId != 0) ? ** (from pp in context.mmlProductsParts
join pa in context.tblParts on pp.PartId equals pa.PartId
where pa.PartNumber.Contains(searchModel.SearchTerm) ||
pa.Keyword.Contains(searchModel.SearchTerm)
&& pp.ProductId == ProductId
select new PartModel
{
PartId = pa.PartId,
Category = GetCategory(pa.CategoryId),
PartNumber = pa.PartNumber,
Keywords = pa.Keyword,
PartDescription = pa.Description,
Price = pa.Price.Value,
Ratio = pa.Ratio.Value,
Tribal = pa.Tribal
}).ToList()
: (from pp in context.mmlProductsParts
join pa in context.tblParts on pp.PartId equals pa.PartId
where pa.PartNumber.Contains(searchModel.SearchTerm) ||
pa.Keyword.Contains(searchModel.SearchTerm)
select new PartModel
{
PartId = pa.PartId,
Category = GetCategory(pa.CategoryId),
PartNumber = pa.PartNumber,
Keywords = pa.Keyword,
PartDescription = pa.Description,
Price = pa.Price.Value,
Ratio = pa.Ratio.Value,
Tribal = pa.Tribal
}