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
Post a Comment