gpt4 book ai didi

c# dapper error when parameter is list 对象类型 <>f__AnonymousType20`1[[System.Int32[] 不存在映射

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:31 26 4
gpt4 key购买 nike

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();

有人能看出我做错了什么吗?

No mapping exists from object type <>f__AnonymousType20`1[[System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=]] to a known managed provider native type.

我从这篇文章中得到了这个想法: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());
}

最佳答案

public static async Task<IEnumerable<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";
{
IEnumerable<dynamic> profitMargin = await conn.QueryAsync<dynamic>(sqlQuery
, new { QuoteId = new[] { 1, 2, 3, 4, 5 } });
}

如果您不将其映射到列表或数组,默认情况下它将是一个 IEnuerable。

关于c# dapper error when parameter is list<int> 对象类型 <>f__AnonymousType20`1[[System.Int32[] 不存在映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39523414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com