Get the App
SLTechnology News&Howtos  ›  Network Security  › 

SQL Server precompilation executes SQLs

Shulou Source: shulou.com Published: 2022-06-01 09:39:45 10月02日 Update

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 ()

Tags: Parameters compilations fields that is data method time is in the empty string problem project Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei MariaDB Linux Apple