title: LiteDB how to insert list of list of object
body: <p>I'm struggling to insert/update my class with a list of list of object into my LiteDB database. I tried several things and possible solutions, but I can't get it working.</p>
  
  <p>Here my classes:</p>
  
  <p>Parent:</p>
  
  <pre><code> [BsonRef("pictogram")]
  public class Pictogram : BasePictogram, IPictogram
  {
        /// &lt;summary&gt;
      /// each pictogram has an unique Id
      /// the Id tpye is Guid
      /// &lt;/summary&gt;
      [BsonId]
      public Guid Id { get; }
  
      /// &lt;summary&gt;
      /// The 2D Array (list of list) which contain the whole matrix of Pixels in it
      /// &lt;/summary&gt;°
      public List&lt;List&lt;IPixel&gt;&gt; Pixels { get; set; }
  }
  </code></pre>
  
  <p>Child:</p>
  
  <pre><code>enter code [BsonRef("pixel")]
  public class Pixel : IPixel
  {
      [BsonId]
      public Guid Id { get; set; }
  
      /// &lt;summary&gt;
      /// the X coordinate of the pixel
      /// &lt;/summary&gt;
      public int X { get; set; }
  
      /// &lt;summary&gt;
      /// the Y coordinate of the pixel
      /// &lt;/summary&gt;
      public int Y { get; set; }
  
      /// &lt;summary&gt;
      /// the color of the pixel
      /// &lt;/summary&gt;
      public Color Color { get; set; }
  
      /// &lt;summary&gt;
      /// defines if the pixel was set from a text or a graphic object
      /// &lt;/summary&gt;
      public PixelSource PixelSource { get; set; }
  }
  </code></pre>
  
  <p>I tried tho map these collections with the BsonMapper:</p>
  
  <pre><code>   public void InsertPictogram(Pictogram pic)
      {
          var mapper = BsonMapper.Global;
  
          mapper.Entity&lt;Pictogram&gt;()
              .DbRef(p =&gt; p.Pixels, "pixel");
  
          if (pic == null) throw new ArgumentNullException(nameof(pic));
          using (var db = new LiteDatabase(_connectionString))
          {
              var pictograms = db.GetCollection&lt;Pictogram&gt;("pictogram");
              var pixels = db.GetCollection&lt;IPixel&gt;("pixel");
  
  
              foreach (var pixel in pic.Pixels.ToList())
              {
                  pixels.Insert(pixel);
              }
  
              pictograms.Insert(pic);
  
          }
      }
  </code></pre>
  
  <p>But I'm getting a nullReferenceException when I try the insert the pic.</p>
  
  <p>Can someone explain me how to work with list of list in LiteDB correctly?</p>
  
  <p>Thanks a lot!
  BR Steff</p>