簡體   English   中英

dapper - 返回INT列表

[英]dapper - return a list of INT

從存儲過程我返回一個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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM