SQL Server precompilation executes SQLs
Problem description:
MVC5 project, get the data by executing sql, but report an error when using precompile execution, field XXXwhich was not supplied.
In fact, it is this parameter that passes a null. Make a judgment before passing the parameter. If it is null, you can assign it to an empty string.
(=
String sql = "select a.ID matchingId Where a.DepId a. UserNameMagnea.TrueNamePowerISNull (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 (sql, sqlParameters). ToList ()