返回INT的列表
本文关键字:列表 INT 返回 | 更新日期: 2023-09-27 17:58:21
从一个存储过程中,我返回一个int
列表,简称
SELECT ID FROM Table
这是使用适配器。下面是我尝试做的事情。我可以使用相同的方法填充一个对象,但不能使用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>