mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.36k stars 1.22k forks source link

[QUESTION] Two-way navigation between entities #2455

Open ssteiner opened 3 months ago

ssteiner commented 3 months ago

I have two entities that are linked together:

public class Admin
{
   public string Id {get; set;}
   public string UserName {get; set;}
   public List<Role> Roles {get; set;}
}

public class Role
{
    public string Id {get; set;}
    public string Name {get; set;}
    public List<Admin> AdminInRole {get; set;
}

BsonMapper.Global.Entity<Admin>()
            .DbRef(x => x.Roles , "roles");
BsonMapper.Global.Entity<Role>()
            .DbRef(x => x.AdminInRole , "admins")

Is there a way to make this work so that if I insert a role into Admin, and then query the role (including AdminInRole) I'd get the admin that has been assigned the role, too?