Nhibernate使用SQL查询来选择项目

时间:2014-03-24 13:56:40

标签: c# nhibernate

我正在努力制定Nhibernate,我终于让它发挥作用了。所以我的第二步是使用costum sql为此选择对象尝试以下内容:

var query = "SELECT * " +
            "from DAGE_I_KS WHERE DATO in (:orderYear));";

var session = mySessionFactory.OpenSession();
var result = session.CreateSQLQuery(query)
                    .AddEntity(typeof(DAGE_I_KS))
                    .SetString("orderYear", "2012")
                    .List<DAGE_I_KS>();

但是我收到了一个sql错误:

could not execute query
[ SELECT *  from DAGE_I_KS WHERE DATO in (?)); ]
  Name:orderYear - Value:2012
[SQL: SELECT *  from DAGE_I_KS WHERE DATO in (?));]

我不确定以下问题是什么问题:

using (mySession.BeginTransaction())
{
    ICriteria criteria = mySession.CreateCriteria<DAGE_I_KS>();
    IList<DAGE_I_KS> list = criteria.List<DAGE_I_KS>();

    mySession.Transaction.Commit();
}

0 个答案:

没有答案