小编Chr*_*ris的帖子

无法将 DBNull.Value 转换为类型“System.Double”。请使用可为 null 的类型

我的object val = method.Invoke line中的代码有问题。我们使用此代码将 mdx 字段映射到我们的实体(集合)。某些数据具有 DBNull 值。所以我做了一项研究来检查 propertyType 是否为 Nullable 并实现了解决方案。请参阅Nullable.GetUnderlyingType。但我仍然遇到这个错误。无法将 DBNull.Value 转换为类型“System.Double”。请使用可为空的类型。

string propertyKey = entry.Key;
PropertyInfo property = entry.Value;
Type propertyType = property.PropertyType;

propertyType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;

object objectNeedingProperty = objectToPopulate;

MethodInfo method = _dataRowExtFieldMethod.MakeGenericMethod(new Type[] { propertyType });
object val = method.Invoke(row, new object[] { row, propertyKey });

property.SetValue(objectNeedingProperty, val, null);
Run Code Online (Sandbox Code Playgroud)

.net c# reflection

4
推荐指数
1
解决办法
7945
查看次数

IActionResult 或 async Task<IActionResult> 有什么优点?

我们将在 dotnet core 2.1 中创建一个新的 API,这个 Web API 将是一个高流量/交易,比如每分钟 10,000 或更高。我通常像下面这样创建我的 API。

[HttpGet("some")]
public IActionResult SomeTask(int id)
{
   var result = _repository.GetData(id)
   return Ok(result);
}
Run Code Online (Sandbox Code Playgroud)

如果我们像下面这样实现我们的 Web API,会有什么好处?

[HttpGet("some")]
public async Task<IActionResult> SomeTask(int id)
{
    await result = _repository.GetData(id);
    return Ok(result);
}
Run Code Online (Sandbox Code Playgroud)

我们还将为这个新 API 使用 EF 核心,如果我们执行异步任务,我们是否也应该使用 EF 异步?

asp.net asp.net-web-api .net-core asp.net-core-webapi

4
推荐指数
1
解决办法
3053
查看次数