2016-07-22 70 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> 
相关问题