Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate: single lazy load property
    text
    copied!<p><strong>Update:</strong> I'm now convinced that the problem lies in the fact that Document is configured as non lazy. The problem is that I don't control the base class and that means I can't change the base props to virtual... </p> <p>After reading the docs, I'm under the assumption that I should be able to have a non lazy class with a lazy property. Is this possible? Here's the code I'm using for mapping my class:</p> <pre><code>public class DocumentoMapping : ClassMap&lt;Documento&gt; { public DocumentoMapping() { Setup(); } private void Setup() { Table("Documentos"); Not.LazyLoad(); Id(doc =&gt; doc.Id, "IdDocumentos") .GeneratedBy.Identity() .Default(0); Map(doc =&gt; doc.NomeDocumento) .Not.Nullable(); Map(doc =&gt; doc.Descricao); Map(doc =&gt; doc.Bytes, "Documento") .CustomSqlType("image") .CustomType&lt;Byte[]&gt;() .LazyLoad() .Length(2000000000); Component(doc =&gt; doc.Acao, accao =&gt; { accao.Map(a =&gt; a.Login); accao.Map(a =&gt; a.Data); accao.Map(a =&gt; a.UserAD) .CustomSqlType("int") .CustomType&lt;ADs&gt;(); }) .Not.LazyLoad(); Map(doc =&gt; doc.IdPedidoAssistencia) .Column("IdPats") .Not.LazyLoad(); } } </code></pre> <p>And here's the code for my class:</p> <pre><code>public class Documento : Entity, IHasAssignedId&lt;int&gt;{ public virtual Byte[] Bytes { get; private set; } public Documento() { NomeDocumento = Descricao = ""; Acao = new Acao("none", DateTime.Now, ADs.Sranet); } public Documento(string nomeDocumento, string descricao, Acao acao) { Contract.Requires(!String.IsNullOrEmpty(nomeDocumento)); Contract.Requires(!String.IsNullOrEmpty(descricao)); Contract.Requires(acao != null); Contract.Ensures(!String.IsNullOrEmpty(NomeDocumento)); Contract.Ensures(!String.IsNullOrEmpty(Descricao)); Contract.Ensures(Acao != null); NomeDocumento = nomeDocumento; Descricao = descricao; Acao = acao; } [DomainSignature] public String NomeDocumento { get; private set; } [DomainSignature] public String Descricao { get; private set; } [DomainSignature] public Acao Acao { get; private set; } internal Int32 IdPedidoAssistencia { get; set; } internal static Documento CriaNovo(String nomeDocumento, String descricao, Byte[] bytes, Acao acao) { Contract.Requires(!String.IsNullOrEmpty(nomeDocumento)); Contract.Requires(!String.IsNullOrEmpty(descricao)); Contract.Requires(bytes != null); Contract.Requires(acao != null); var documento = new Documento(nomeDocumento, descricao, acao) { Bytes = bytes }; return documento; } public void ModificaBytes(Byte[] bytes) { Contract.Requires(bytes != null); Bytes = bytes; } public void SetAssignedIdTo(int assignedId) { Id = assignedId; } [ContractInvariantMethod] private void Invariants() { Contract.Invariant(NomeDocumento != null); Contract.Invariant(Descricao != null); Contract.Invariant(Acao != null); } } </code></pre> <p>Base classes are the just for the basic stuff, ie, setting Id and injecting base code for instance comparison. At first sight, I can't really see anything wrong with this code. I mean, the property is virtual, the mapping says it should be virtual, so why does loading it with Get forces a complete load of the properties? For instance, this code: var d = sess.Get(148);</p> <p>Ends up generating sql for loading all the properties on the table. Did I get this wrong?</p> <p>thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload