0
I need the string "hql" that would be my select to convert to int so I can compare values in an if.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BlogWeb.ViewsModels;
using BlogWeb.DAO;
using BlogWeb.Models;
using BlogWeb.Filters;
using BlogWeb.Controllers;
using NHibernate;
using BlogWeb.Infra;
namespace BlogWeb.Controllers
{
public class GerenciamentoKM
{
private Rota p;
private ISession session;
public GerenciamentoKM(ISession session, Rota p, RotaDAO dao)
{
this.p = p;
this.session = session;
}
public void soma(Rota post)
{
string hql = "SELECT p.Km_Atual FROM Rota WHERE p.Km_Atual as LAST_INSERT_ID(Km_Atual)";
int km_t = Convert.ToInt16(hql);
if (km_t <= p.Km_Atual)
{
ITransaction tx = session.BeginTransaction();
session.Update(post);
tx.Commit();
}
}
}
}
This does not work, I tried later running the query before
public void soma(Rota post)
{
string hql = "SELECT p.Km_Atual FROM Rota WHERE p.Km_Atual as LAST_INSERT_ID(Km_Atual)";
IQuery query = session.CreateQuery(hql);
query.List<Rota>();
int km_t = Convert.ToInt16(hql);
if (km_t <= p.Km_Atual)
{
ITransaction tx = session.BeginTransaction();
session.Update(post);
tx.Commit();
}
}
That way it didn’t work either, so I also tried to start her from the outside and pull to the public.
public IList<Rota> Lista()
{
string hql = "SELECT p.Km_Atual FROM Rota WHERE p.Km_Atual as LAST_INSERT_ID(Km_Atual)";
IQuery query = session.CreateQuery(hql);
return query.List<Rota>();
}
public void soma(Rota post)
{
string hql = "SELECT p.Km_Atual FROM Rota WHERE p.Km_Atual as LAST_INSERT_ID(Km_Atual)";
if (Lista <= p.Km_Atual)
{
ITransaction tx = session.BeginTransaction();
session.Update(post);
tx.Commit();
}
}
Wouldn’t you have to run the query first? And then convert the result?
– Artur Trapp
I tried to run with the query but still, it does not convert to integer.
– Guilherme Padovam
You need to run the query before trying to do anything. Your current code is trying to convert the string
"SELECT p.Km_Atual ..."
. Understands?– Jéf Bueno
I tried to run the query before trying to convert the data but now it informs that it is part of a group of methods, and if I try to put in the same public void, the void will not stop using the query’s Return.
– Guilherme Padovam
@Guilhermepadovam You can’t understand what you’re talking about. Please try to be clearer. Give more details, [Dit] the question may help.
– Jéf Bueno
I changed the question to show what I tried to do to run this code.
– Guilherme Padovam
When I try to update for information exchange, this error appears: System.Formatexception was not manipulated by user code Hresult=-2146233033 Message=The input character string was not in a correct format.
– Guilherme Padovam
About your tests as some have already said you should run the query first and then get the result and convert. Check the hints on this link. http://gabsferreira.com/como-fazer-queries-no-nhibernate-criteria-queryover-linq-to-nhibernate-hql-e-sql/
– Cleidson_eng