当前位置: 代码迷 >> ASP.NET >> 请问泛型实体显式转换为IList
  详细解决方案

请问泛型实体显式转换为IList

热度:1212   发布时间:2013-02-25 00:00:00.0
请教泛型实体显式转换为IList
请教一下,返回数据集合的第一行。提示“无法将类型DataInfo隐式转换为IList<DataInfo>,存在一个显式转换”,但我用 as IList<DataInfo>,数据就消失了。请问要怎样转换??谢谢!

C# code
public IList<DataInfo> GetListById{string sql = @"select * from message where (targetid=:ID or sourceid=:ID)";IList<DataInfo> list = _session.CreateQuery(sql).Set<int>("ID ", ID).List<DataInfo>();            if (list != null && list.Count > 0)            {               return list[0]; //这里提示“无法将类型DataInfo隐式转换为IList<DataInfo>,存在一个显式转换”            }            return null;}


------解决方案--------------------------------------------------------
return new List<DataInfo>{list[0]}