Good Day,
I read a lot of tutorials around the internet and created some exemples in VS2005 + MSSQL2005, but im having some trouble im my example and i dont know what to do anymore. I made the .hbm files and implemented the classes. The inserting is doing fine but when i try to make the "CreateQuery" with the "where" clause or the .Get method. It gives me the message "could not execute query" and show a long sql query with some "?" (interrogation marks)
I'll post the classes and the .hbm files, if anyone could help me ill thanks a lot, im desespered.
SQL Tables:
Code:
dbo.tblPagamentoInss
-pgiCodigo (PK,char(4),not null)
- pdgiDescricao (varchar(255),null)
dbo.Inss
- insCodigo(PK,int,not null)
- insNome (varchar(30),null)
- insFpas (int,null)
- insCodigoTerceiros(int,null)
- insCodigoAcidenteTrabalho (char(9), null)
- insContribuicaoEmpresa (numeric (4,2), null)
- insAcidenteTrabalho (numeric (4,2),null)
- insTerceiros(numeric (4,2), null)
- insCodigoPgamentoInss (FK,char(4), not null)
CLASSES
Code:
public class Inss
{
public virtual int Codigo
{get { return _codigo; } set { _codigo = value; }}
public virtual string Nome
{get { return _nome; }set { _nome = value; }}
public virtual int FPas
{get { return _fPas; }set { _fPas = value; }}
public virtual int CodigoTerceiros
{get { return _codigoTerceiros; }set { _codigoTerceiros = value;}}
public virtual string CodigoAcidenteTrabalho
{get { return _codigoAcidenteTrabalho;}set { _codigoAcidenteTrabalho = value; }}
public virtual decimal ContribuicaoEmpresa
{get { return _contribuicaoEmpresa; }set { _contribuicaoEmpresa = value; }}
public virtual decimal AcidenteTrabalho
{get { return _acidenteTrabalho; }set { _acidenteTrabalho = value; }}
public virtual decimal Terceiros
{get { return _terceiros; }set { _terceiros = value; }}
public virtual PagamentoInss PagamentoInss
{get { return _pagamentoInss; }set { _pagamentoInss = value; }}
}
public class PagamentoInss
{
public virtual String Codigo
{get { return _codigo; }set { _codigo = value; }}
public virtual string Descricao
{get { return _descricao; }set { _descricao = value; }}
public virtual IList inssList
{get{return _inssList;}set{_inssList=value;}}
public virtual String DescricaoConcat
{get { return Convert.ToString(this.Codigo) + " - " + this.Descricao; }}
}
HBM FILES:Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Entidades.Inss, Entidades" table="tblInss" lazy="true">
<id name="Codigo" column="insCodigo" type="Int32">
<generator class="increment"/>
</id>
<property name="Nome" column="insNome" not-null="true" type="String" />
<property name="FPas" column="insFpas" type="Int32" />
<property name="CodigoTerceiros" column="insCodigoTerceiros" type="Int32" />
<property name="CodigoAcidenteTrabalho" column="insCodAcidenteTrabalho" type="String" />
<property name="ContribuicaoEmpresa" column="insContribuicaoEmpresa" type="Decimal" />
<property name="AcidenteTrabalho" column="insAcidenteTrabalho" type="Decimal" />
<property name="Terceiros" column="insTerceiros" type="Decimal" />
<many-to-one name="PagamentoInss" column="insCodigoPagamentoInss" not-null="true" fetch="join" cascade="save-update" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Entidades.PagamentoInss,Entidades" table="tblPagamentoInss" lazy="true">
<id name="Codigo" column="pgiCodigo" type="String">
<generator class="increment"/>
</id>
<bag name="inssList" table="tblInss" cascade="all" fetch="join" inverse="true">
<key column="PK_INSS" />
<one-to-many class="Entidades.Inss,Entidades" />
</bag>
<property name="Descricao" column="pgiDescricao" type="String" />
</class>
</hibernate-mapping>
NOW the problem:
When i do this works fine:
IQuery query = session.CreateQuery("From Inss");
return query.List();
when i do this
DONT WORK!:
IQuery query = session.CreateQuery("From Inss where Nome=:name");
query.SetString("name", "sometext");
and gives me the error:
could not execute query (some sql query)