2016-07-22 40 views
4

的列表從一個存儲過程,我回國的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。我相信解決方案非常簡單。只是他們中的一個星期五......

乾杯

+2

嘗試更換'選擇(行=>新INT {ID = row.ID})'和'選擇(行=> row.ID)' –

回答

2

這是非常相似,但與.ToList() as IList<int>

var ids = connection.Query<int>("storedprocedure", 
param, transaction:transaction, commandType: CommandType.StoredProcedure) 
.ToList() as IList<int> 
相關問題