I need the string "hql" which would be my select to convert to int so I can do the comparison of 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 after 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 did not work either, so I tried to start it on the outside and pull it to 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();
}
}