我怎样才能收集一个集合

时间:2014-06-26 08:18:06

标签: c# collections

此代码:

IList<string> quids;
quids = db.Database.SqlQuery<string>("dbo.getById @Id",
                new SqlParameter { ParameterName = "Id", Value = 1 });

产生以下错误消息:

  

无法隐式转换类型'System.Data.Entity.Infrastructure.DbRawSqlQuery'到   'System.Collections.Generic.IList'。

     

存在显式转换(您是否错过了演员?)

有人可以向我解释如何投射集合吗?

1 个答案:

答案 0 :(得分:8)

IList<string> result = oldCollection.ToList();

DbRawSqlQuery<T>不实现IList<T>接口(因此,不能直接转换)。但它实现了IEnumerable<T>,因此您可以调用.ToList()

相关问题