BsonMapper.Global.RegisterType<LogEvent>(
serialize: (LogEvent) => LiteDB.JsonSerializer.Deserialize(JsonConvert.SerializeObject(LogEvent)),
deserialize: (BsonValue) => JsonConvert.DeserializeObject<LogEvent>(BsonValue.AsDocument.ToString(), new LogEventJsonConverter(), new LogEventPropertyValueConverter())
);
Delete<T>(T Entity, string collectionName)
or DeleteMany<T>(IEnumerable<T> entities, string collectionName)
as input. My class handles passing entities through to the LiteRepository but does not know anything about the entities passed in, so I can not get the id to pass in or to create a predicate. Is there a way to pass in an entity to be deleted?
Need your help on deserializing a List.
i create dynamically a query and get the result like this:
var resultSet = _store.Execute(sql).ToEnumerable().Select(s => BsonMapper.Global.Deserialize<SongData>(s)).ToList();
In my SongData class i have:
public List<string> PictureHashList => _pictureHashList;
Using LiteDBStudio i can see that i have values in the list, but the above query returns an empty list.
Any ideas?
using var _db = new LiteDatabase(_path);
var _dbCol = _db.GetCollection("CollectionName", BsonAutoId.Int32);
$.Properties.customer.Properties[*].FirstName any = 'Jonathan'
. Similarly, if you want to check whether all of these are equal to a value, you can use $.Properties.customer.Properties[*].FirstName all = 'Jonathan'
DateTime
field or even make it your Id field. Due to the BSON spec, LiteDB only stores dates up to the miliseconds (losing a bit of precision). There is a simple workaround for that though, so let me know if you need help with that.
:memory:
as its datafile or by using the LiteDatabase
ctor that takes a Stream (you can pass a MemoryStream
to it)
@raizam You can create an index over a
DateTime
field or even make it your Id field. Due to the BSON spec, LiteDB only stores dates up to the miliseconds (losing a bit of precision). There is a simple workaround for that though, so let me know if you need help with that.
will the DateTime order be preserved when I'll iterate the records? in both indexed/key scenarios?
db.Execute("select $._id from collection").ToList()
. This will give you a list of BsonDocument
s containing the id
var ids = db.Execute("select $._id from collection").ToEnumerable().Select(doc => doc["_id"].AsInt32).ToList();
(assuming the id is Int32
)
DbRef