Я пытаюсь вставить / обновить свой класс со списком объектов в моей базе данных LiteDB. Я пробовал несколько вещей и возможных решений, но не могу заставить его работать.
Вот мои занятия:
Родитель:
[BsonRef("pictogram")]
public class Pictogram : BasePictogram, IPictogram
{
/// <summary>
/// each pictogram has an unique Id
/// the Id tpye is Guid
/// </summary>
[BsonId]
public Guid Id { get; }
/// <summary>
/// The 2D Array (list of list) which contain the whole matrix of Pixels in it
/// </summary>°
public List<List<IPixel>> Pixels { get; set; }
}
Ребенок:
enter code [BsonRef("pixel")]
public class Pixel : IPixel
{
[BsonId]
public Guid Id { get; set; }
/// <summary>
/// the X coordinate of the pixel
/// </summary>
public int X { get; set; }
/// <summary>
/// the Y coordinate of the pixel
/// </summary>
public int Y { get; set; }
/// <summary>
/// the color of the pixel
/// </summary>
public Color Color { get; set; }
/// <summary>
/// defines if the pixel was set from a text or a graphic object
/// </summary>
public PixelSource PixelSource { get; set; }
}
Я пытался сопоставить эти коллекции с помощью BsonMapper:
public void InsertPictogram(Pictogram pic)
{
var mapper = BsonMapper.Global;
mapper.Entity<Pictogram>()
.DbRef(p => p.Pixels, "pixel");
if (pic == null) throw new ArgumentNullException(nameof(pic));
using (var db = new LiteDatabase(_connectionString))
{
var pictograms = db.GetCollection<Pictogram>("pictogram");
var pixels = db.GetCollection<IPixel>("pixel");
foreach (var pixel in pic.Pixels.ToList())
{
pixels.Insert(pixel);
}
pictograms.Insert(pic);
}
}
Но я получаю исключение nullReferenceException при попытке вставить картинку.
Может кто-нибудь объяснить, как правильно работать со списком списков в LiteDB?
Большое спасибо!
BR Steff