問題描述:
MVC5項目,利用執行sql的方式擷取資料,但是在利用預編譯執行的時候報錯了,字段XXXwhich was not supplied.
其實就是這個參數傳了個null導緻的。在傳參數之前做個判斷,如果為null就指派為空串即可。
String sql = "select a.Id,a.UserName,a.TrueName,ISNULL(b.OTM, '0') as Flag from SysUser a left join FIX_MatchingModel b on cast(a.Id as varchar) = b.OTM and b.Id = @matchingId Where a.DepId = @DepId order by b.OTM desc";
SqlParameter[] sqlParameters = { new SqlParameter { ParameterName = "matchingId", Value = matchingId }, new SqlParameter { ParameterName = "DepId", Value = depId } };
DbContexts DbContext = new DbContexts();
return DbContext.Database.SqlQuery<UserView>(sql, sqlParameters).ToList();
本文轉自 sshpp 51CTO部落格,原文連結:http://blog.51cto.com/12902932/1927608,如需轉載請自行聯系原作者