mercredi 27 septembre 2017

Nhibernate GetType method usage in SetParameter with CreateSqlQuery for custom types

I have a request named TransactionRequest and it has a TrnxType object in it , like below:

public class TransactionRequest
{
 public Type TrnxType { get; set; }  
}

I pass trnxType value to my nhibernate query below with queryOver :

sqlQueryWithQueryOver.Where(x =>x.GetType() == transactionRequest.TrnxType );

So here is my question, with QueryOver I can get the type I'm working on and use GetType() method but below situation I can't :

var sqlQuery= "Select * from ABC this_ where this_.TrnxType= :trnxType";
var sqlList = session.CreateSQLQuery(sqlQuery)             
                 .SetParameter("trnxType", TransactionRequest.TrnxType);

How can we provide x.GetType() equivalent in CreateSqlQuery way? Because this way I got exception about type cast. (By the way trnxType is an integer in db.) Thanks from now.





Aucun commentaire:

Enregistrer un commentaire