简体   繁体   中英

Nhibernate Delete 3

Tried to delete using nhibernate, but got caught on a error like

" 'tItemVantagem' is not mapped"

but it is. Any suggestions?

_session.Delete(string.Format("DELETE FROM tItemVantagem WHERE IdContraCheque in(select IdContraCheque from tContraCheque  where IdCompetencia ={0})", competencia));
_session.Delete(string.Format("DELETE FROM tItemDesconto WHERE IdContraCheque in(select IdContraCheque from tContraCheque  where IdCompetencia ={0})", competencia));
_session.Delete(string.Format("DELETE FROM tContraCheque WHERE IdCompetencia ={0}", competencia));

Here is the mapping :

public ItemVantagemMAP()
    {
        Table("tItemVantagem");
        Id(x => x.Identificador, c => { c.Generator(Generators.Identity); c.Column("IdItemVantagem"); });
        ManyToOne(x => x.TipoVantagem, y => { y.Cascade(Cascade.None); y.Update(false); y.Insert(false); y.Fetch(FetchKind.Join); y.Lazy(LazyRelation.NoLazy); y.Column("IdTpItemVantagem"); });
        Property(x => x.HorasPercentual, y => { y.Column("QtHorasPercentual"); });
        Property(x => x.Valor, y => { y.Column("VlItemVantagem"); });
    }

The Delete() method takes an HQL string which operates in terms of your mapped classes, not your table names.

From your mapping, tItemVantagem is the name of the table. I sincerely doubt that is the name or your mapped class (which you have oddly left out of the mapping you posted).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM