c# - 我怎样才能让我的 dapper 结果成为一个列表?

标签 c# dapper

为什么我不能在上面添加 .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/

相关文章:

c# - SQLite 作为 SQL Server 的内存数据库

c# - 为什么Dapper在执行查询时需要对事务的引用?

c# - Java Annotations 和 C# Attributes 有什么异同?

c# - 如何使用 DbParameter 将多个参数传递给 c# 中的参数化查询?

c# - 在 C# 中从 URL 中删除 anchor

C# 编码(C# 调用 C++ DLL)

c# - 可以查询 NotMapped 属性吗?

c# - 在 mvc 中使用 dapper 的动态结果

c# - 实现轻量级 TransactionScope

dapper - 什么 .Net orms 或 MicroOrms 支持异步操作和 PostgreSql