2011-01-08 18 views
1

これは私のコードですORACLE 10gのためのNHibernate .NET "クエリを実行できませんでした"

私は間違っていますか?

public IList listdataserviceplan(String custid) 
{ 
    using (ISession session = NHibernateHelper.OpenSession()) 
    { 
     string query = ” select a.ServicePlanId as ServicePlanId , 
           a.ServiceDetail as ServiceDetail,” 
      + ” a.DateServiceFix as DateServiceFix ,a.DateService as DateService,” 
      + ” a.CaseNotSupport as CaseNotSupport ,a.ServiceChangeName as ServiceChangeName,” 
      + ” a.DateServiceNew as DateServiceNew ,a.MaterialChange as MaterialChange,” 
      + ” a.ServiceGuarantee as ServiceGuarantee ,a.ServiceMaintenance as ServiceMaintenance,” 
      + ” a.ServiceCharge as ServiceCharge” 
      + ” from BicIsu.Core.Domain.ServicePlan as a” 
      + ” where 1=1″ 
      + ” and a.CustId = ‘” + custid + “‘ ” 
      + ” order by a.ServicePlanId”; 

     var cons = session.CreateQuery(query).List(); 
     return cons; 
    } 
} 
+0

NHibernateの外で手動で実行するとクエリが機能しますか? –

答えて

0

私はエラーは表示されませんが、それはそれらの複雑な魔法の文字列と関係があると思います。試してみてください:

string query = @"select a.ServicePlanId, 
         a.ServiceDetail, 
         a.DateServiceFix, 
         a.DateService, 
         a.CaseNotSupport, 
         a.ServiceChangeName, 
         a.DateServiceNew, 
         a.MaterialChange, 
         a.ServiceGuarantee, 
         a.ServiceMaintenance, 
         a.ServiceCharge 
       from ServicePlan as a 
       where 1=1 
       and a.CustId = :custId 
       order by a.ServicePlanId"; 

var result = session.CreateQuery(query) 
        .SetParameter("custId", custid) 
        .List(); 

FYI、Ad-hoc mapping with NHibernate.

0
おそらく

ないHQLクエリを記述するための最良の方法。なぜあなたはStringBuilderクラスを使いませんか?私はこれが答えではありません知っている

var hqlQuery= new StringBuilder(); 
hqlQuery.Append("select a from ClassA"); 
hqlQuery.AppendFormat("where a.Id={0}",idVal); 

return session.List<ClassA>(hqlQuery.toString()); 

: それはこのようなものになります。間違いなくコードを手伝ってくれるでしょう。

問題が発生しました。あなたが得ているエラーは何ですか?そのクエリは発砲しているのですか、例外を取得していますか?

関連する問題