Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a null parameter with Dapper

Tags:

dapper

People also ask

How do I pass a null value in dapper?

GetCacheInfo(Identity identity) in C:\Dev\dapper-git\Dapper\SqlMapper. cs:line 908 at Dapper. SqlMapper. Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\Dev\dapper-git\Dapper\SqlMapper.


I think you should be able to do it by casting null to the appropiate type. Let's assume RouteId is an integer:

connection.Execute("spLMS_UpdateLMSLCarrier", new { RouteId = (int?)null, CarrierId = carrierID, UserId = userID, TotalRouteRateCarrierId = totalRouteRateCarrierId }, commandType: CommandType.StoredProcedure);

The problem you are encountering when using regular null is likely that the compiler cannot infer the type of RouteId in the anonymous type when just using null without the cast.