NHibernate 之 “ 值“System.Object[]”不是“”类型,不能在此泛型集合中使用。 参数名: value”
2012-06-13 09:22
921 查看
public IList<OutStorageDataView> GetItemList(int Brand_ID, int pageNo, int pageSize, out int TotalNumber) { IList<OutStorageDataView> List; ICriteria critRecordCount = NHibernateSessionReader.CreateCriteria(typeof(OutStorageDataView)); //查询总数(未入数据) TotalNumber = Convert.ToInt32(critRecordCount.SetProjection(Projections.Count("Item_ID")).UniqueResult()); ////获得当前页的数据 //ICriteria crit = NHibernateSessionReader.CreateCriteria(typeof(OutStorageDataView)); //crit.Add(Restrictions.Eq("Brand_ID", Brand_ID)); //crit.SetFirstResult((pageNo - 1) * pageSize) // .SetMaxResults(pageSize); //List = crit.List<OutStorageDataView>(); //return List; //------------ IQuery crit = NHibernateSessionReader.CreateSQLQuery("SELECT [Item_ID],[Item_Title],[Item_URL],[SearchEngine_Name],[Task_KeyWord],[Brand_Name],[Item_SDate],[Item_CDate],[Admin_Name],[Brand_ID] FROM [OutStorageDataView]"); //crit.Add(Restrictions.Eq("Brand_ID", Brand_ID)); crit.SetFirstResult((pageNo - 1) * pageSize) .SetMaxResults(pageSize); //List = (List<OutStorageDataView>)crit.List<OutStorageDataView>(); List = crit.List<OutStorageDataView>(); return List; } #endregion }
报错:
值“System.Object[]”不是“IWOMTracker.Data.Model.OutStorageDataView”类型,不能在此泛型集合中使用。
参数名: value
修正:
List = crit.List<OutStorageDataView>();因为默认返回的数值类型是System.Object[] 不不是“IWOMTracker.Data.Model.OutStorageDataView”类型
改成:
IQuery crit = NHibernateSessionReader.CreateSQLQuery("SELECT [Item_ID],[Item_Title],[Item_URL],[SearchEngine_Name],[Task_KeyWord],[Brand_Name],[Item_SDate],[Item_CDate],[Admin_Name],[Brand_ID] FROM [OutStorageDataView]", "t",
typeof(OutStorageDataView));
//crit.Add(Restrictions.Eq("Brand_ID", Brand_ID));
crit.SetFirstResult((pageNo - 1) * pageSize)
.SetMaxResults(pageSize);
List = (List<OutStorageDataView>)(crit.List<OutStorageDataView>());
return List;
进行强类型转换,就OK了。
相关文章推荐
- 使用泛型 类型System.Collections.Generic.KeyValuePair需要2个类型参数
- 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数
- Effective JavaScript Item 46 优先使用数组而不是Object类型来表示有顺序的集合
- 使用泛型类型System.Collections.Generic.Icomparer &lt;T&gt; 需要一个类型参数
- 类型 List 不是通用的;不能使用参数 <String> 将它参数化
- Effective JavaScript Item 46 优先使用数组而不是Object类型来表示有顺序的集合
- 无法将 DBNull.Value 强制转换为类型“System.DateTime”。请使用可空类型
- 使用可为空值的数据类型和System.Nullable(Of T)泛型类型
- 泛型约束where条件的使用(可以通过类型参数动态反射创建实例)
- SpringBank 开发日志 重新设计Action调用Service的参数传递 使用泛型解决类型转换问题
- dataType参数不能为空,未处理的“System.ArgumentNullException”类型的异常出现在 mscorlib.dll 中
- 解决三星手机post请求时参数包括集合,封装成JSONObject,结果不是数组而是数组的地址问题
- SpannableStringBuilder连续调用setSpan时参数Object what不能使用同一个引用
- 泛型集合类型,赋予集合业务意义,增强集合的抽象使用
- Java集合中使用泛型参数及泛型上下限的问题
- 契约操作不能使用引用对象作为参数,只允许使用基本类型或数据契约
- c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode
- Java基础之泛型——使用通配符类型参数(TryWildCard)
- mybatis中使用map类型参数,其中key为列名,value为列值
- 使用泛型后的List集合类型的三种遍历方式