读书人

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

发布时间: 2012-03-28 15:40:03 作者: rapoo

请教泛型实体显式转换为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]}

读书人网 >asp.net

热点推荐