gpt4 book ai didi

c# - 无法等待系统集合通用 ienumerable

转载 作者:行者123 更新时间:2023-11-30 23:27:24 25 4
gpt4 key购买 nike

<分区>

我是异步编程的新手,有人要求我在不破坏现有功能的情况下实现异步。在我的 Web API 服务层中,我有这样的东西:

public IList<Entities.Case.CreateCaseOutput> createCase(ARC.Donor.Data.Entities.Case.CreateCaseInput CreateCaseInput, ARC.Donor.Data.Entities.Case.SaveCaseSearchInput SaveCaseSearchInput)
{
Repository rep = new Repository();
string RequestType = "Insert";
string strSPQuery = string.Empty;
List<object> listParam = new List<object>();
SQL.CaseSQL.getCreateCaseParameters(CreateCaseInput, RequestType, out strSPQuery, out listParam);
var AcctLst = rep.ExecuteStoredProcedure<Entities.Case.CreateCaseOutput>(strSPQuery, listParam).ToList();
if (!string.IsNullOrEmpty(AcctLst.ElementAt(0).o_case_seq.ToString()))
saveCaseSearch(SaveCaseSearchInput, AcctLst.ElementAt(0).o_case_seq);
return AcctLst;
}

并且这个 SaveCaseSearch 是异步实现的:

public async Task<IList<Entities.Case.SaveCaseSearchOutput>> saveCaseSearch(ARC.Donor.Data.Entities.Case.SaveCaseSearchInput SaveCaseSearchInput,Int64? case_key)
{
Repository rep = new Repository();
string strSPQuery = string.Empty;
List<object> listParam = new List<object>();
SQL.CaseSQL.getSaveCaseSearchParameters(SaveCaseSearchInput, case_key,out strSPQuery, out listParam);
var AcctLst = await rep.ExecuteStoredProcedure<Entities.Case.SaveCaseSearchOutput>(strSPQuery, listParam).ToList();
return AcctLst;
}

但是它说:

enter image description here

ExecuteStoredProcedure 看起来像:

public IEnumerable<T> ExecuteStoredProcedure<T>(string strSPQuery, List<object> parameters)
{
_msg = "";
try
{
this._context.Database.CommandTimeout = 280;

return this._context.Database.SqlQuery<T>(strSPQuery, parameters.ToArray());

}
catch (Exception ex)
{
_msg = "ERROR: " + ex.Message;
if (ex.InnerException != null) { _msg += "INNER EXCEPTION: " + ex.InnerException; }
log.Info(_msg);
}
return null;
}

可以做什么? ToListAsync() 值得一看吗?当我尝试它时,我得到了

enter image description here

并更改 ExecuteStoredProcedure 定义产生

public Task<IEnumerable<T>> ExecuteStoredProcedure<T>(string strSPQuery, List<object> parameters)
{
_msg = "";
try
{
this._context.Database.CommandTimeout = 280;

return this._context.Database.SqlQuery<T>(strSPQuery, parameters.ToArray());

}
catch (Exception ex)
{
_msg = "ERROR: " + ex.Message;
if (ex.InnerException != null) { _msg += "INNER EXCEPTION: " + ex.InnerException; }
log.Info(_msg);
}
return null;
}

错误:

错误 13 无法将类型 'System.Data.Entity.Infrastructure.DbRawSqlQuery' 隐式转换为 'System.Threading.Tasks.Task>' C:\Users\m1034699\Desktop\Stuart_V2_12042016\Stuart Web Service\ARC .Donor.Data\Repository.cs 115 24 ARC.Donor.Data

我不知道该怎么做。请帮忙。

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