gpt4 book ai didi

c# - 将 Task 转换为 decimal

转载 作者:太空宇宙 更新时间:2023-11-03 17:38:06 25 4
gpt4 key购买 nike

当我尝试转换 Task<decimal> 时出现此错误至 decimal :

Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

这是我的方法:

public async Task<decimal> GetTotalProposalAmount()
{
using (DataContext db = new DataContext())
{
var total = db.Database.SqlQuery<decimal>("Get_ProposalTotal", null);
return await total.FirstAsync();
}
}

我在 Controller 中调用它:

public async Task<ActionResult> Index(int? page, string search)
{

model.Proposaltotal = Convert.ToDecimal(GetTotalProposalAmount());
return View(model);
}

最佳答案

您只需等待任务:

model.Proposaltotal = await GetTotalProposalAmount();

这与您的构建错误无关,just add the reference it asks for .

关于c# - 将 Task<decimal> 转换为 decimal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49796747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com