title: Could not initialize collection - Fluent Nhibernate
body: <p>I'm getting an error when processing a collection of objects</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Toma.cs</strong></p>
  
  <pre><code>public class Toma
  {
      public virtual int TomaID { get; protected set; }
      public virtual DateTime FechaCarga { get; set; }
      public virtual String TipoDocumento { get; set; }
      public virtual String NroDocumento { get; set; }
      public virtual Boolean Procesada { get; set; }
  
      private IList&lt;Dedo&gt; dedos;
      public virtual IList&lt;Dedo&gt; Dedos 
      {
          get { return dedos; }
          protected set { dedos = value; }
      }
      private IList&lt;Firma&gt; firmas;
      public virtual IList&lt;Firma&gt; Firmas 
      {
          get { return firmas; }
          protected set { firmas = value; } 
      }
      private IList&lt;Foto&gt; fotos;
      public virtual IList&lt;Foto&gt; Fotos 
      {
          get { return fotos; }
          protected set { fotos = value; }
      }
  
      public Toma()
      {
          dedos = new List&lt;Dedo&gt;();
          firmas = new List&lt;Firma&gt;();
          fotos = new List&lt;Foto&gt;();
      }
  
      public virtual void MarcarComoProcesada()
      {
          this.Procesada = true;
          this.Dedos[0].Imagen = new Byte[] { 0x20 };
          this.Firmas[0].Imagen = new Byte[] { 0x20 };
          this.Fotos[0].Imagen = new Byte[] { 0x20 };
          //throw new NotImplementedException();
      }
  
      internal static IList&lt;Toma&gt; GetAll()
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p><strong>Dedo.cs</strong></p>
  
  <pre><code>public class Dedo
  {
      public virtual int DedoID { get; protected set; }
      public virtual Byte[] Imagen { get; set; }
      public virtual Toma Toma { get; set; }
  }
  </code></pre>
  
  <p><strong>Firma.cs</strong></p>
  
  <pre><code>public class Firma
  {
      public virtual int FirmaID { get; protected set; }
      public virtual Byte[] Imagen { get; set; }
      public virtual Toma Toma { get; set; }
  }
  </code></pre>
  
  <p><strong>Foto.cs</strong></p>
  
  <pre><code>public class Foto
  {
      public virtual int FotoID { get; protected set; }
      public virtual Byte[] Imagen { get; set; }
      public virtual Toma Toma { get; set; }
  }
  </code></pre>
  
  <p>My mappings:</p>
  
  <p><strong>Toma.cs</strong></p>
  
  <pre><code>public class TomaMap : ClassMap&lt;Toma&gt;
  {
      public TomaMap()
      {
          Table("Bio_Toma");
          Id(x=&gt;x.TomaID).Column("TomaId");
          Map(x =&gt; x.FechaCarga);
          Map(x =&gt; x.TipoDocumento);
          Map(x =&gt; x.NroDocumento);
          Map(x =&gt; x.Procesada);
          HasMany(x =&gt; x.Dedos).Inverse().Cascade.All().KeyColumn("DedoID").Inverse();
          HasMany(x =&gt; x.Firmas).Inverse().Cascade.All().KeyColumn("FirmaID").Inverse();
          HasMany(x =&gt; x.Fotos).Inverse().Cascade.All().KeyColumn("FotoID").Inverse();
      }
  }
  </code></pre>
  
  <p><strong>Dedo.cs</strong></p>
  
  <pre><code>public class DedoMap : ClassMap&lt;Dedo&gt;
  {
      public DedoMap()
      {
          Table("Bio_Dedo");
          Id(x =&gt; x.DedoID);
          Map(x =&gt; x.Imagen);
          References(x =&gt; x.Toma).Column("TomaID");
      }
  }
  </code></pre>
  
  <p><strong>Firma.cs</strong></p>
  
  <pre><code>public class FirmaMap : ClassMap&lt;Firma&gt;
  {
      public FirmaMap()
      {
          Table("Bio_firma");
          Id(x =&gt; x.FirmaID);
          Map(x =&gt; x.Imagen);
          References(x =&gt; x.Toma).Column("TomaID");
      }
  }
  </code></pre>
  
  <p><strong>Foto.cs</strong></p>
  
  <pre><code>public class FotoMap : ClassMap&lt;Foto&gt;
  {
      public FotoMap()
      {
          Table("Bio_Foto");
          Id(x =&gt; x.FotoID);
          Map(x =&gt; x.Imagen);
          References(x =&gt; x.Toma).Column("TomaID");
      }
  }
  </code></pre>
  
  <p>And where I'm getting the error:</p>
  
  <pre><code>                foreach (Toma toma in tomas)
                  {
                        ... some other things...
  
                      if(toma.Fotos != null)
                      {
                          foreach (Foto foto in toma.Fotos) // HERE
                              fs.Write(foto.Imagen);
                      }
                       .... more code ....
                  }
  </code></pre>
  
  <p>Reviewing questions and making the changes suggested there, could not correct the error.
  I'm thinking if the error is the number of objects that have to process. The number of "Tomas" object is 41k.
  There is some kind of limit on the session object for these cases?</p>
  
  <p>Edit: 
  Exception</p>
  
  <pre><code>'NHibernate.Exceptions.GenericADOException' en NHibernate.dll
  
   Additional information:could not initialize a collection
   [MJYS.DGSPR.Infraestructura.Entidades.Toma.Firmas#1039][SQL: SELECT firmas0_.FirmaID
   as FirmaID1_, firmas0_.FirmaID as FirmaID1_0_, firmas0_.Imagen as Imagen1_0_,
   firmas0_.TomaID as TomaID1_0_ FROM Bio_firma firmas0_ WHERE firmas0_.FirmaID=?]
  </code></pre>