Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将NHibernate CreateSqlQuery()结果转换为ObservableCollection_Nhibernate_Observablecollection - Fatal编程技术网

将NHibernate CreateSqlQuery()结果转换为ObservableCollection

将NHibernate CreateSqlQuery()结果转换为ObservableCollection,nhibernate,observablecollection,Nhibernate,Observablecollection,我有以下建议: using (ISession session = Config.SessionFactory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { // This is a System.Collections.Array

我有以下建议:

            using (ISession session = Config.SessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    // This is a System.Collections.ArrayList,contains all my records returned from the session
                    var list  = session.CreateSQLQuery(selectQuery).List(); 

                    // I want to put these records in an ObservableCollection of a specific Type
                    // Something like htis:
                    MyCollection = new ObservableCollection<MyType>(list);
                }
            }
   var query = session.CreateSQLQuery(selectQuery).AddEntity(typeof(MyType));
   myObservableCollection = new ObservableCollection<MyType>(query.List<MyType>());
使用(ISession session=Config.SessionFactory.OpenSession())
{
使用(ITransaction transaction=session.BeginTransaction())
{
//这是一个System.Collections.ArrayList,包含会话返回的所有记录
var list=session.CreateSQLQuery(selectQuery.list();
//我想把这些记录放在一个特定类型的可观察集合中
//类似htis:
MyCollection=新的可观察集合(列表);
}
}

这是行不通的,铸造在这里不是一个选项。有没有办法将我的返回列表放入ObservaleCollection?

我已使用以下命令填写ObservaleCollection:

            using (ISession session = Config.SessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    // This is a System.Collections.ArrayList,contains all my records returned from the session
                    var list  = session.CreateSQLQuery(selectQuery).List(); 

                    // I want to put these records in an ObservableCollection of a specific Type
                    // Something like htis:
                    MyCollection = new ObservableCollection<MyType>(list);
                }
            }
   var query = session.CreateSQLQuery(selectQuery).AddEntity(typeof(MyType));
   myObservableCollection = new ObservableCollection<MyType>(query.List<MyType>());
var query=session.CreateSQLQuery(selectQuery).AddEntity(typeof(MyType));
myObservableCollection=新的ObservableCollection(query.List());
列表()返回ArrayList。ArrayList中的每个值都有一个对象类型的值。 它不能直接转换成任何特定的类。所以,创建一个映射文件,这样只有您才能获得所需对象的列表。