开发者

Test for CreateSQLQuery

开发者 https://www.devze.com 2023-03-05 20:34 出处:网络
I use NHibernate CreateSQLQuery method to get DTO objects of my departments. string query = @\"SELECT * FROM Departments\";

I use NHibernate CreateSQLQuery method to get DTO objects of my departments.

string query = @"SELECT * FROM Departments";
IList<Object[]> resultList = Session.CreateSQLQuery(query)...

and it works well. But also I want to write a test and it fails when I write:

 [Test]
 public void CanGetTreeDto()
  {

            IList<DepartmentDto> resultList =  _departmentRepository.GetTreeLi开发者_如何学PythonstDto(idContract);
...
        }

It throws SQLiteException and writes "could not execute query". Could anybody help?


You need ad-hoc mapping:

IList<DepartmentDto> result = Session.CreateSQLQuery(query)
                                     .SetResultTransformer(Transformers.AliasToBean(typeof(DepartmentDto)))
                                     .List<DepartmentDto>();

Also, you might need to be explicit about the columns as well as its names.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号