none
Query Nested document using Linq in DocumentDB RRS feed

  • Question

  • Hi,

    public class Asset { public Guid Id { get; set; } public List<Subscription> SubTypes { get; set; } } public class Subscription { Public string SubName { get; set; } public string SubType { get; set; } } IQueryable<Asset> subentity = AssetCollection.Query<Asset>(); subentity = subentity.Where(x => x.SubTypes.Any(y => y.SubType =="ABC")); var results= subentity.AsEnumerable().ToList();

    when I execute above linq expression I'm getting exception as

    Method 'Any' is not supported on DOCDB. So how can I query on child document collection type using linq.

    I have seen some samples using sql where I can query on child collection. But not seen any on Linq

    I also tried to use where instead of Any but ran in to same exception saying where clause is not supported.

    subentity = subentity.Where(x => x.SubTypes.Where(y => y.SubType =="ABC").Count()>0);

    Can someone let me know how to query using Linq on a child collection using IQueryable.


    Thanks, Amar


    • Edited by Amar Movva Friday, April 22, 2016 6:38 AM
    Friday, April 22, 2016 6:37 AM

All replies

  • Use IN operator instead of ANY
    Monday, April 25, 2016 5:23 AM
  • Following Himanshu2016's answer, you could try:

    IQueryable<Asset> subentity = AssetCollection.Query<Asset>();
    subentity = subentity.Where(x => x.SubTypes.Contains("ABC"));
    var results= subentity.AsEnumerable().ToList();

    Tuesday, April 26, 2016 12:35 PM
  • Hi @Ealsur! 

    I need a similar query but, following your code sample, x.SubTypes is a list of objects and not string and what I need would be something like:

    subentity.Where(x => x.SubTypes.Any(st => st.Name == "ABC")))

    Any is not supported and I've been trying nested llinq and I'm not finding any way to do it... Can you give me a hand? For other long-time ago Autocosmos teammate guy ;)

    Monday, May 8, 2017 4:29 PM