This is trying to give an insert in the table using a string containing a sql code ... when I use the DELETE command it runs perfectly now when I squeeze the insert no ... the insert runs straight into the database. Follow the code:
public void Inserir(AjusteAdministrativoPorFilial ajusteAdministrativo, string id_user)
{/* alterar */
try
{
ValidarAjusteAdministrativoPorFilial(ajusteAdministrativo);
string strFiliais = "";
for(int i=0; i<ajusteAdministrativo.AjusteAdministrativoPorFilialFiliais.Count; i++)
{
strFiliais += ajusteAdministrativo.AjusteAdministrativoPorFilialFiliais[i].CodigoFilial.ToString() + ',';
}
strFiliais = strFiliais.Substring(0, strFiliais.Length-1);
string sqlQuery = String.Format(@"
INSERT INTO MAG_T_AJUSTE_USUARIO_LOG
(ID_AJUSTE_USUARIO_LOG,
ID_USER,
FILIAIS,
DATA)
SELECT
10 AS ID_AJUSTE_USUARIO_LOG,
'{0}' AS ID_USER,
'{1}' AS FILIAIS,
'16/02/2018 17:54:21' AS DATA
FROM DUAL;
", id_user, strFiliais);
//Repositorio.Query(sqlQuery);
Repositorio.test(sqlQuery);
//Repositorio.Database.ExecuteSqlCommand(sqlQuery.ToString());
Repositorio.Commit();
}
catch (Exception ex)
{
Repositorio.RollBack();
throw ex;
}
}
}
IRepository
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using NHibernate;
using NHibernate.Criterion;
using System.Data.Entity;
namespace MagazineLuiza.UC.APS.Dominio.Interfaces.Repositorios
{
public interface IRepositorio : IDisposable
{
int test(string sql);
void Commit();
void RollBack();
void BeginTransaction();
}
}
repository
public int test(string sql)
{
return Session.CreateSQLQuery(sql).ExecuteUpdate();
}