我正在使用Dapper执行存储过程并获得单行响应。我的代码如下:
public async Task<Provider> GetProvider(int id)
{
try
{
using (var connection = _connectionFactory.Create())
{
var provider = await connection.QueryFirstOrDefaultAsync("GetProvider",
new {
Id = id
},
commandType: CommandType.StoredProcedure);
return new Provider()
{
DimProviderId = provider.DimProviderID,
ProviderNumber = provider.ProviderNumber,
FirstName = provider.FirstName,
MiddleName = provider.MiddleName,
LastName = provider.LastName,
};
}
}
....
当我调试此函数时,我可以看到提供程序对象包含我要从中获取的属性,但是尝试访问provider.DimProviderID时出现以下错误:
Cannot convert null to 'int' because it is a non-nullable value type
这是我看到变量提供程序时看到的,您可以看到DimProviderID属性在那里并且具有值:
这是我的提供者类:
public class Provider
{
public int DimProviderId { get; set; }
public string ProviderNumber { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set;
}
我应该如何访问结果的值?