I am trying to implement a "if exists, update, otherwise insert" data access method in NHibernate. My database is Oracle 10g.
I get this error "I can’t execute the request for mass manipulation" when I try to run this code, if I start the insert or update the personality, it works fine.
Thanks!
string sql = @"DECLARE
CntOfRow Number(10,0);
BEGIN
SELECT count(*)
INTO CntOfRow
FROM Table1
WHERE
QueID=:QueID
IF CntOfRow=0 THEN
INSERT INTO Table1 ...;
ELSE
UPDATE Table1 ... ;
END IF;
END;";
INHibernateSession session = NHibernateSessionManager.Instance.Session;
try
{
session.BeginTransaction();
ISQLQuery query = session.GetISession().CreateSQLQuery(sql.Replace(System.Environment.NewLine, " "));
query.SetParameter("QueID", queID);
query.ExecuteUpdate();
session.CommitTransaction();
}
catch (Exception ex)
{
session.RollbackTransaction();
throw;
}
source
share