Tôi có một thủ tục lưu sẵn có tham số không có giá trị mặc định, nhưng nó có thể là rỗng. Nhưng tôi không thể tìm ra cách vượt qua null với Dapper. Tôi có thể làm điều đó tốt trong ADO.Cách chuyển một tham số rỗng với Dapper
connection.Execute("spLMS_UpdateLMSLCarrier", new { **RouteId = DBNull.Value**, CarrierId = carrierID, UserId = userID, TotalRouteRateCarrierId = totalRouteRateCarrierId },
commandType: CommandType.StoredProcedure);
Ngoại lệ:
System.NotSupportedException was caught
Message=The member RouteId of type System.DBNull cannot be used as a parameter value
Source=Dapper
StackTrace:
at Dapper.SqlMapper.LookupDbType(Type type, String name) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 348
at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 1251
at Dapper.SqlMapper.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.cs:line 532
at Rating.Domain.Services.OrderRatingQueueService.UpdateLMSLCarrier(Int32 totalRouteRateCarrierId, Int32 carrierID, Int32 userID) in C:\DevProjects\Component\Main\Source\Rating\Source\Rating.Domain\Services\OrderRatingQueueService.cs:line 52
at Benchmarking.Program.OrderRatingQueue() in C:\DevProjects\Component\Main\Source\Benchmarking\Source\Benchmarking\Program.cs:line 81
at Benchmarking.Program.Main(String[] args) in C:\DevProjects\Component\Main\Source\Benchmarking\Source\Benchmarking\Program.cs:line 28
InnerException:
Không thể rời khỏi RouteId tắt, mang lại cho tôi một lỗi mà nói nó yêu cầu. Không thể sử dụng null thông thường hoặc là cung cấp cho tôi một lỗi khác. Không thể thay đổi thủ tục được lưu trữ, nó không thuộc về tôi.
Loại RouteId là gì? – driis
Đó là một int. Và trước khi bạn nói bất cứ điều gì, hãy nhớ, tôi có thể làm điều này tốt trong ADO mà không có ngoại lệ. –