-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Version
Windows 10.
Same with library version 5.0.21 and 6.0.0.-pre74
Describe the bug
When using a collection annotated with DbRef (regardless of attribute or fluent), the master entity is saved with references, but when retrieved, the referenced entities are not loaded. No visible collection is created for the referenced entity.
More attempts here: https://stackoverflow.com/questions/79873876/litedb-does-not-load-bsonref-items?noredirect=1#comment140953309_79873876
Code to Reproduce
void Main()
{
var fn = Path.Join(Path.GetTempPath(), "tmp2.db").Dump("DB");
File.Delete(fn);
var db = new LiteDatabase($"Filename={fn}; Connection=shared");
var col = db.GetCollection<Master>();
col.Insert(new Master() { MasterData = "1", Details = [new() { Id = 1, Data = "A" }, new() { Id = 2, Data = "B" }, new() { Id = 3, Data = "Y" } ] });
col.Insert(new Master() { MasterData = "2", Details = [new() { Id = 4, Data = "M" }, new() { Id = 5, Data = "N" } ] });
col.Insert(new Master() { MasterData = "3", Details = [new() { Id = 6, Data = "X" } ] });
col
.Include(x => x.Details)
.FindOne(_ => true)
.Dump();
col
.Query()
.Include(x => x.Details)
.First()
.Dump();
db.Dispose();
var repo = new LiteRepository($"Filename={fn}; Connection=shared");
repo.Query<Master>()
.Include(x => x.Details)
.First()
.Dump();
}
public class Master
{
[BsonId]
public ObjectId Id { get; set; }
public required string MasterData { get; set; }
[BsonRef]
public List<Detail> Details { get; set; }
}
public class Detail
{
[BsonId]
public int Id { get; set; }
public required string Data { get; set; }
}Expected behavior
Details collection to be created, populated with the proper content and retrieved when included.
Screenshots/Stacktrace
Additional context
By removing DbRef, collection is embedded.
fil-at-werma