从存储过程中,我将返回一个int
列表-就像
SELECT ID FROM Table
这是使用dapper。以下是我尝试做的尝试。我可以使用相同的方法填充对象,但不能填充int
对象
List<int> ids = new List<int>();
int id = 0;
// Trying to fill a list of ints here
ids = connection.Query("storedprocedure", param, transaction: transaction, commandType: CommandType.StoredProcedure).Select(row => new int { id = row.ID }).ToList();
我相信这与声明末尾的=> new int
有关。我相信解决方案非常简单。其中只有星期五。
我认为您应该从查询中指定您期望的类型,如下所示:
var ids = connection.Query<int>("storedprocedure",
param,
transaction: transaction,
commandType: CommandType.StoredProcedure);
您可以检查此执行查询并将结果映射到强类型列表以获取更多信息。
这非常相似,但.ToList() as IList<int>
var ids = connection.Query<int>("storedprocedure",
param, transaction:transaction, commandType: CommandType.StoredProcedure)
.ToList() as IList<int>