c# - Dynamic Where in linq MVC -
i trying filter model 2 dropdown in mvc project
var model = (from x in db.table.... join y in db.table...).where(where)...
my logic is
string = string.empty; if (search.anno != null) = " anno = " + search.anno ; if (search.cliente != null) { if (!string.isnullorempty(where)) { += " , codice_cliente = '" + search.cliente + "'"; } else { = " codice_cliente = '" + search.cliente + "'"; } }
i error: system.linq.dynamic.parseexception: character literal must contain 1 character
i in += " , codice_cliente = '" + search.cliente + "'";
i saw apex @ end '"
how can solve
you need use double equals expression , double quotes strings string = string.empty;
if (search.anno != null) = " anno == " + search.anno ; if (search.cliente != null) { if (!string.isnullorempty(where)) { += " , codice_cliente == \"" + search.cliente + "\""; } else { = " codice_cliente == \"" + search.cliente + "\""; } }
note prone sql injection , should avoided, should use parameters, this:
var model = (from x in db.table.... join y in db.table...).where(wherestring, params)...
Comments
Post a Comment