【发布时间】:2020-02-17 10:21:29
【问题描述】:
我正在 asp.net 核心中实现 CRUD。我创建了如下方法:
public async Task<int> AccessAPIApplicantHistoryDouble(int t)
{
var task = APIApplicantHistoryLog(t);
int result = await task;
return result;
}
private int APIApplicantHistoryLog(int myAPIApplicantId)
{
APIApplicantHistoryDto mydto = new APIApplicantHistoryDto();
_context.Set<ApiApplicantHistory>().Add(new ApiApplicantHistory
{
ApiApplicantId = myAPIApplicantId,
Date = null,
SentResponseType = 0,
UnconfirmedReason = 0,
LastReqStatus = 0,
Description = "",
IdDeleted = false // This field should be totally omited from SQL server
}) ;
_context.SaveChangesAsync();
var myArrayList = new List<int>();
var result = from x in _context.ApiApplicantHistory where x.ApiApplicantId == myAPIApplicantId
select new { x.Id };
foreach (var i in result)
myArrayList.Add(i.Id);
return myArrayList.Max();
}
在 await 行中出现如下错误:
如果有人建议我解决该错误的解决方案,我将不胜感激。
【问题讨论】:
-
APIApplicantHistoryLog 不是“异步”类,因此您不能“等待”它。 “await” 期望一个类返回一个 Task 对象。 APIApplicantHistoryLog 返回 int。使其异步并返回 Task
。另外,有“await _context.SaveChangesAsync();”
标签: asp.net-core-mvc