.ToList()
? Intellisense唯一允许的是
.ToString()
。
//..
string sqlQuery = "SELECT sum(SellingPrice) as SellingPrice, sum(MarkupPercent) as MarkupPercent, sum(MarkupAmount) as MarkupAmount FROM ProfitMargins WHERE QuoteId in @QuoteId group by multiplier";
{
List<ProfitMargin> profitMargin = (List<ProfitMargin>)await conn.QueryAsync<List<ProfitMargin>>(sqlQuery, new { QuoteId = QuoteIds.ToArray()}) //would like to add .ToList() here;
return profitMargin;
}
//..
update
我认为问题与conn.queryAsync(conn是context.database.connection.connectionstring)而不是context.database.sqlquery
trory改变了这一点。
or
var results = await conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()});
List<ProfitMargin> profitMargin = results.ToList();
我认为您正在尝试打电话
Task
try:
.ToList()
orList<ProfitMargin> profitMargin = new List<ProfitMargin>(await conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()}));
当@amy说,您需要使用
List<ProfitMargin> profitMargin = (await conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()})).ToList();
在等待评估时返回
conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()}))
。
是以前答案的补充:
从C#12中,也可以使用收集表达式。这简化了转换为:
Task<IEnumerable<ProfitMargin>>