SQL TO LINQ
如何将以下sql语句转换为Linq
string sql="select * from student"
sql+= " CP_ID='" + cp_id + "'";
if (status != 9)
sql += " And Status='" + status.ToString() + "'";
if (nameorcode != "")
sql += " And (Operator_Name like '%" + nameorcode + "%' or Operator_Code like '%" + nameorcode + "%')";
------解决方案--------------------from a in dc.Students
where a.CP_ID==cp_id &&
(status==9
------解决方案--------------------a.Status==status.ToString()) &&
(namerorode==""
------解决方案-------------------- a.Operator_Name.Contains(nameorcode)
------解决方案-------------------- a.Operator_Code.Contains(nameorcode))
select a;
不知道哥的思路对不对
------解决方案-------------------- var query;
if (status != 9)
query=from i in student
where (i.CP_ID= cp_id&&i.Status= status)
select i;
if (nameorcode != "")
query=from i in student
where (i.CP_ID= cp_id
&&( i.Operator_Name.Contains(nameorcode)
------解决方案-------------------- i.Operator_Code.Contains(nameorcode )
)
)
select i;
------解决方案--------------------参考:
http://blog.csdn.net/q107770540/article/details/5724013