Unproxy property mapping nhibernate

489 Views Asked by At

you can put a property without a proxy? because I need to get the value of it. Below is the mapping:

  public class MateriaPrimaMap : ClassMap<MateriaPrima> {

    #region Construtor

    public MateriaPrimaMap() {
        Table("MATERIAPRIMA");           

        Id(m => m.Id).Column("MPR_CD");

        Map(m => m.Descricao)
        .Column("MPR_DS")
        .Not.Nullable().Length(30);

        Map(m => m.Ativo)
         .Column("MPR_ATIVO")
         .Not.Nullable();

        Version(m => m.Version).Column("MPR_DT_LK").Generated.Always();
    }

    #endregion
}}

image proxy proprety: enter image description here

2

There are 2 best solutions below

0
On

You can use the mapping of NHibernate, which let's you map a property of another entity (related with the main one) as if it were part of it. See here: http://nhibernate.info/doc/nhibernate-reference/mapping.html#mapping-declaration-join.

0
On

If you have a proxy, you can get the identifier using INHibernateProxy reference here.

If you do not what to deal with proxies, just add an additional properties and map them, be sure to use .Not.Insert().Not.Update() to avoid mapping problems.

Map(m => m.DescricaoId)
    .Column("MPR_DS")
    .Not.Insert().Not.Update();

Map(m => m.AtivoId)
    .Column("MPR_ATIVO")
    .Not.Insert().Not.Update();