0

I want to show results where w.DrawDate contains (LIKE %year%) the year.

return View(db.Euro.Select(p => p).Where(w => w.DrawDate == year).ToList());

As seen in Like condition in MVC4 using lambda, i should use the Contains() method, but it isn't available.

So, how can i make w.DrawDate == year into w.DrawDate LIKE %year%?

Community
  • 1
  • 1
Mr Billy
  • 151
  • 1
  • 2
  • 13
  • maybe duplicate http://stackoverflow.com/questions/14346961/linq-where-string-contains-or-string-indexof – pix Oct 16 '16 at 18:45
  • 1
    `.Where(w => w.DrawDate.Year == year)`. And you can remove the unnecessary `.Select(p => p)`) –  Oct 16 '16 at 23:37
  • Thanks for the "unnecessary Select" tip, but let's assume 'DrawDate' is a string and you don't have a Year property, i want to find if "2016" is in "ABCD2016EFGH". – Mr Billy Oct 17 '16 at 13:02

1 Answers1

0

You already have the answer:

View(db.Euro.Where(w => w.DrawDate.Contains(year)).ToList());

And you're probably just missing a namespace

kbaccouche
  • 4,575
  • 11
  • 43
  • 65
  • Well i `Ctrl + .` on Contains() and it suggests nothing. So, what namespace i am missing to get Contains() method available? The absence of Contains() is critical to my question's existence. – Mr Billy Oct 17 '16 at 13:52
  • Actually Contains() is a method for String so you don't need to import a special namespace to use it. If you copy paste my code, does it compile ? Maybe it's just a bug with your intellisense... – kbaccouche Oct 17 '16 at 14:00