Marten: linq support for child collection and child collection of child collection

Created on 7 Sep 2017  路  7Comments  路  Source: JasperFx/marten

Hello. I know that linq support is very difficult. From documentation I understood some queries are supported for searching in child collections.
But what about if child collection is not simple type array? Like this:

    public class BaseClass : PocoStorableObject
    {
        public List<SubChild> SubChildren { get; set; }
        public SubChild SingleSubChild { get; set; }

        public string Name { get; set; }
    }

    public class SubChild
    {
        public List<SubSubChild> SubSubChildren { get; set; }
        public SubSubChild SingleSubSubChild { get; set; }

        public int SubAge { get; set; }
        public string SubName { get; set; }
    }

    public class SubSubChild
    {
        public string SubSubName { get; set; }
    }

And queries like this doesn't work:

var query1 = martenQueryable.Where(o => o.SubChildren.Any()).ToList();
var query2 = martenQueryable.Where(o => o.SubChildren.Any(c => c.SubSubChildren != null)).ToList();
var query3 = martenQueryable.Where(o => o.SubChildren.Any(c => c.SubSubChildren.Any())).ToList();
var query4 = martenQueryable.Where(o => o.SubChildren.Any(c => Marten.Util.StringExtensionMethods.Contains(c.SubName, "IVAN", StringComparison.OrdinalIgnoreCase))).ToList();
var query5 = martenQueryable.Where(o => o.SubChildren.Any(c => Marten.Util.StringExtensionMethods.Contains(c.SingleSubSubChild.SubSubName, "IVAN", StringComparison.OrdinalIgnoreCase))).ToList();

string[] names = new string[] {"name1, name2"};
var query6 = martenQueryable.Where(o => o.SubChildren.Any(c => c.SingleSubSubChild.SubSubName.IsOneOf(names))).ToList();

How difficult is it to implement query support for such child collections?
Will there be support for such requests in the near future?

bug linq

Most helpful comment

Got it!!!!!!!

All 7 comments

I've just faced same issue. :/
@KopIlya, the only workaround I have for this is to use raw SQL where conditions.

See currently supported scenarios. https://github.com/JasperFx/marten/pull/1107 We added some improvements for the inner collections, but it's not yet finished.
I added tests for @KopIlya scenarios in https://github.com/JasperFx/marten/pull/1265.

@jeremydmiller do you plan to solve them in your Linq overhaul part 1?

Hey folks, this is done in a v4 branch.

Ugh, I closed the wrong issue. Sorry folks.

This is all me. Might actually work OOTB after the v4 changes, but we'll see...

Got it!!!!!!!

@jeremydmiller Does this fix rely on v4 branch code? Or could it be applied to a v3 bugfix release?
We would love to have it released asap, so to determine how much workaround we should do, it would be nice to know when we could expect this bugfix. If it has to be v4, when do you suppose a RC will appear?
Awesome product by the way :)

Was this page helpful?
0 / 5 - 0 ratings