c# - Multiple where statements in Entity Framework -
database structure sample:
department table -departmentid
facility table -facility id -departmentid (fk) -block -level -name -etc
i trying select database ef using 2 clause. not sure went wrong @ clause. stuck @ it. please , advice. have googled on internet cannot find solution it.
string departmentid = "sit"; string block = "l"; string level = "4"; string name = "l.425"; using (var db = new kioskcontext()) { var facilitys = f in db.facilitys
where clause select departmentid equals sit , block or level or name contains alphabets. please advice how should write statement 2 clause. thank you!
f.department.departmentid == departmentid && (f.block.contains("%" + block + "%") || f.level.contains("%" + level + "%") || f.name.contains("%" + name + "%"))
remaining of query statement select facilities
orderby f.facilityid select new { f.facilityid, f.departmentid, f.description, f.block, f.level, f.name, f.openhours, f.closehours, f.maxbktime, f.maxbkunits, f.minbktime, f.minbkunits }; foreach (var fac in facilitys) { facobject facobject = new facobject(fac.facilityid, fac.departmentid, fac.description, fac.block, fac.level, fac.name, fac.openhours, fac.closehours, fac.maxbktime, fac.maxbkunits, fac.minbktime, fac.minbkunits); sqlfaclist.add(facobject); } }
remove "%" various contains
clauses, sql cruft not need.
where f.department.departmentid == departmentid && (f.block.contains(block) || f.level.contains(level) || f.name.contains(name ))
remember linq not sql!
Comments
Post a Comment