Search based on a set of keywords

前端 未结 7 1008
慢半拍i
慢半拍i 2020-12-31 08:52

I need to make a search based on a set of keywords, that return all the Ads related with those keywords. Then the result is a list of Categories with the Ads Count for each

7条回答
  •  囚心锁ツ
    2020-12-31 09:36

    this may not be the direct answer, but in such "multiple parameter search" situations i just forget about anything and do the simple thing, for ex: Search By Car Manufacturer, CategoryId, MillageMax, Price :

    var searchResults = from c in carDb.Cars
    where (c.Manufacturer.Contains(Manufacturer) || Manufacturer == null) &&
                     (c.CategoryId == CategoryId || CategoryId == null) &&
                        (c.Millage <= MillageMax || MillageMax== null) &&
                              (c.Price <= Price  || Price == null) 
    select c
    

    now if any of the parameters is null it cancels the containing line by making the whole expression in brackets True and so it does not take a part in search any more

提交回复
热议问题