NHibernate 之 “ 值“System.Object[]”不是“”类型,不能在此泛型集合中使用。 参数名: value”

        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了。

你可能感兴趣的:(list,url)