为什么我不能在上面添加 .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;
}
//..
更新
我认为问题与 conn.queryasync(conn 是 context.Database.Connection.ConnectionString)而不是 context.Database.SqlQuery 有关
最佳答案
试试改成这个。
List<ProfitMargin> profitMargin = (await conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()})).ToList();
或者
var results = await conn.QueryAsync<ProfitMargin>(sqlQuery, new { QuoteId = QuoteIds.ToArray()});
List<ProfitMargin> profitMargin = results.ToList();
我认为您在尝试调用 .ToList()
时遇到了 Task
对象
关于c# - 我怎样才能让我的 dapper 结果成为一个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601711/