How to ignore a property of entity ?

33 views
Skip to first unread message

Fernando Paiva

unread,
Sep 20, 2016, 6:22:55 PM9/20/16
to Fluent NHibernate
I'm trying ignore a property of a entity. I found a lot of examples but still can't make this. How could do this ?

trying.

Entity

public class Caixa {

       
public virtual long id                      { set; get; }
       
public virtual DateTime dtOcorrencia        { set; get; }
       
public virtual String historico             { set; get; }
       
public virtual int tipoOcorrencia           { set; get; } //1 entrada, 2 saida
       
public virtual decimal valorOcorrencia      { set; get; }
       
public virtual FormaPagamento formaPagto    { set; get; }

       
//must ignore
       
public IList<Caixa> report = new List<Caixa>();
       
       
public Caixa () {
       
}

       
public IList<Caixa> getReport() {
           
return report;
       
}
   
}

The Mapping

public class CaixaMap : ClassMap<Caixa> {
       
public CaixaMap() {            
           
Table("CAIXA");
           
Id(c => c.id).GeneratedBy.Native();
           
Map(c => c.dtOcorrencia).CustomType<DateTime>();
           
Map(c => c.historico);
           
Map(c => c.tipoOcorrencia).CustomType<int>();
           
Map(c => c.valorOcorrencia).CustomType<decimal>().Precision(15).Scale(2);            
           
Map(c => c.formaPagto).CustomType<GenericEnumMapper<FormaPagamento>>();
           
Map(c => c.report); //ignore          
       
}
   
}

Mapping

FluentConfiguration _config = Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(
                                                                        x
=> x.Server(HOST).
                                                                         
Username(USER).
                                                                         
Password(PASSWORD).
                                                                         
Database(DB)
                                                                       
))
                                                                       
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<CaixaMap>())
                                                                       
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true));

            session
= _config.BuildSessionFactory();
           
return session;


Gleb Chermennov

unread,
Sep 21, 2016, 5:50:18 AM9/21/16
to Fluent NHibernate
Have you tried not to map this property at all? Remove the `Map(=> c.report);` line and try again

среда, 21 сентября 2016 г., 1:22:55 UTC+3 пользователь Fernando Paiva написал:

mwpowellhtx

unread,
Sep 21, 2016, 7:48:08 AM9/21/16
to Fluent NHibernate
On Tuesday, September 20, 2016 at 6:22:55 PM UTC-4, Fernando Paiva wrote:
> I'm trying ignore a property of a entity. I found a lot of examples but still can't make this. How could do this ?

Also, be aware that a proxy class is generated. Not sure what effect a field will have on things. It may need to be a public virtual property; minimum virtual protected internal.
Reply all
Reply to author
Forward
0 new messages