Litedb: Will nested Includes or IncludeAll() be re-included in v5?

Created on 12 Aug 2019  路  6Comments  路  Source: mbdavid/LiteDB

Hey Mauricio,

I was wondering, if there will be a re-include of the IncludeAll() like in v4? (or even better a nested Include w/ or w/o circular references)

My generic service function:

public T SingleOrDefault<T>(Expression<Func<T, bool>> expression)
{
    if (TenantExist(ConnectionString))
    {
        using (var db = new LiteDatabase(ConnectionString))
        {
            var collection = db.GetCollection<T>(typeof(T).Name.ToLower());
            return collection.IncludeAll().Find(expression).FirstOrDefault();
        }
    }
    else
        return default;
}

Thanks for your awesome work!

question

All 6 comments

Update: Will the IncludeAll ever come back? atm it's a blocking feature for us to migrate.

@srcmkr have you tried using BsonExpression ?

I ask because it seems you should be able to, but I haven't been able to get it to work beyond a single level with [*]. And it's not documented if you can or how.

https://www.litedb.org/docs/expressions/

Actually it looks like Parent.ChildArray[*].ChildArray[*] works

Indeed, the further levels are interesting, but one of the most challenging thing is the abstraction / generalization of the request.
We have too many models to create a separate service for each of them, so we started to use generic T.
Due to this, we can't pass or know the max depth, even ChildArray[*] works great.
Maybe we'll find a way to execute the ChildArray[*] recursivly, but the IncludeAll worked great so far.

Ah, gotcha. Totally understand -- you don't want to have to worry about property types / names. Hm. Well. I bet something could be done with reflection to build the BsonExpressions from property names and whether or not they're array types or not.

Side note: I've noticed you seem to need to include every level:

.Include(BsonExpression.Create("$.Projects[*]"))
.Include(BsonExpression.Create("$.Projects[*].Scans[*]"))
.Include(BsonExpression.Create("$.Projects[*].Scans[*].NetDevices[*]"))

I would also love to see IncludeAll coming to v5. For us this is a blocking issue as well for the same reasons as for @srcmkr
Are there any updates on this?

Was this page helpful?
0 / 5 - 0 ratings