I am trying to save collection of the strings to LiteDb
using (var db = new LiteDatabase(@"MyData.db"))
{
var col = db.GetCollection<string>("Writers");
col.Insert("Mark Twain");
col.Insert("Jack London");
}
It throws "Object reference not set to an instance of an object." at LiteDB.BsonMapper.ToDocument[T](T entity) on Insert.
Code like this works:
public class Writer
{
public string Name { get; set; }
}
using (var db = new LiteDatabase(@"MyData.db"))
{
var col = db.GetCollection<Writer>("Writers");
col.Insert(new Writer { Name = "Mark Twain" });
col.Insert(new Writer { Name = "Jack London" });
}
Why? What's wrong with the string?