【发布时间】:2016-09-16 03:38:36
【问题描述】:
string sqlQuery = "SELECT SellingPrice, MarkupPercent, MarkupAmount FROM ProfitMargins WHERE QuoteId in @QuoteId";
var profitMargin = await ctx.Database.SqlQuery<dynamic>(sqlQuery,
new { QuoteId = new[] { 1, 2, 3, 4, 5 } }
//String.Join(", ", QuoteIds.ToArray()))).ToListAsync();
谁能看出我做错了什么?
对象类型不存在映射 f__AnonymousType20`1[[System.Int32[], mscorlib, 版本=4.0.0.0, Culture=neutral, PublicKeyToken=]] 到已知的托管提供者本地 输入。
我从这篇文章中得到了这个想法:SELECT * FROM X WHERE id IN (…) with Dapper ORM 回答者:@LukeH
更新:
我需要将它返回到一个列表中。查看我的整个功能,我已经根据@JFM发布的答案更改了代码,但现在无法添加.ToListAsync
@JFM
public static async Task<List<dynamic>> GetProfitMargin(List<int> QuoteIds)
{
using (var conn = new SqlConnection(new MYContext().Database.Connection.ConnectionString))
{
string sqlQuery = "SELECT SellingPrice, MarkupPercent, MarkupAmount FROM ProfitMargins WHERE QuoteId in @QuoteId";
{
var profitMargin = conn.Query<dynamic>(sqlQuery
, new { QuoteId = new[] { 1, 2, 3, 4, 5 } }).ToListAsync());
}
【问题讨论】:
-
您缺少
await的toListAsync。它是否适用于常规.ToList()