c# - How can Convert traditional ADO.Net search to Linq Entity -
first, sorry bad english. in traditional ado.net used function search , got datatable of rows show in gridview or ...
public datatable gettabledata(string fieldname, string value) { datatable ds = new datatable(); sqlconnection scon = new sqlconnection("data source=.;initial catalog=researchpackdb;integrated security=true;"); scon.open(); string str = string.format("select * v_scientificnews {0} {1}", fieldname, value); sqldataadapter sda = new sqldataadapter(str, scon); sda.fill(ds); scon.close(); return ds; } now want rewrite function linq entity, function this!!
public list<v_scientificnews> getnews(string fieldname, string value) { var q = (from r in _entities.v_scientificnews select r) .where(?????????????); return q.tolist(); } if have idea please tell me. thanks
you try following one:
public list<v_scientificnews> getnewsbyfieldname(string value) { var q = (from r in _entities.v_scientificnews r.fieldname.contains(value) select r); return q.tolist(); } or one:
public list<v_scientificnews> getnewsbyfieldname(string value) { var q = _entities.v_scientificnews.where(x=>x.fieldname.contains(value)); return q.tolist(); } so instance, if want scientific news, property called name contains value, declare method below:
public list<v_scientificnews> getnewsbyname(string value) { var q = (from r in _entities.v_scientificnews r.name.contains(value) select r); return q.tolist(); }
Comments
Post a Comment