ef防止sql注入的示例:
ef作為一個orm框架,本身放置了sql的注入,例如查詢視圖"select * from VM where 條件 = {0}"時的方法:
function bool SS(string no)
{
try{
string sql = "select count(*) from Students where StudentNo=@No";
var args = new DbParameter[] {
new SqlParameter { ParameterName = "NO", Value = no},
};
return DataContext.SqlQuery(sql, args).FirstOrDefault() > 0;
}
catch(Exception ex)
{
...
}
}