c# - Using where all on linq -


i trying implement search function application, want happen send list if there no keyword specified , have where clause.

here action:

public actionresult classes(string keyword ="") {         employeecontext emp = new employeecontext();          list<classlist> asd = (from subj in emp.subjects                                join prof in emp.professors on subj.id equals prof.id                                join dep in emp.departments on prof.id equals dep.id                                subj.subj == keyword                                select new classlist()                                {                                    id = subj.id,                                    subj = subj.subj,                                    days = subj.days,                                    cstart = subj.cstart,                                    cend = subj.cend,                                    units = subj.units,                                    fname = prof.fname,                                    lname = prof.lname,                                    status = prof.status,                                    department = dep.dname,                                    isselected = false                                }).tolist();          return view(asd); } 

i researched , says use 'all' doesn't work. don't want make if else statement depending if keyword empty or no since make code ugly. subj property name of subject.

you this

where subj.subj == keyword || keyword=="" 

or this, don't need separate where

from subj in emp.subjects.where(x=>x.subj == keyword || keyword=="") join prof in emp.professors..... 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -