Search code examples
databasenosqlravendb

Advanced NoSQL Query (RavenDB)


I'm trying to run a query that gets all of my references, but it isn't working. What I have right now is

from UserGroups 
where Id="ActionGroup" 
select Accomplishments.ID, Accomplishments.Accomplish

But I need only the Accomplishments.Accomplish that belong in my other collection ActivityAccomplishments and these are nested in another object.

To be exact, I'm trying to figure out how to query the UserGroups collection and only look at the one with id="ActionGroup". After that I need all of the Accomplishments.Accomplish strings within the UserGroup list to be filtered out if they don't match a id in ActivityAccomplishment.

Basically, in the UserGroup I'm looking at it's List Accomplishments needs to filter out all strings within the Acc class that don't match an Id in ActivityAccomplishments. Can someone please help me.

Here are the classes I'm using.

public class UserGroups
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public List<Acc> Accomplishments { get; set; }
}

public class Acc
{
    public string Id { get; set; }
    public List<string> Accomplish { get; set; }
}

public class ActivityAccomplishments
{
    public string Id { get; set; }
}

Solution

  • try this:

    from UserGroups 
    where Id = "ActionGroup" AND Accomplishments[].Accomplish != "theIdYouDontWant" 
    select Accomplishments[].Accomplish as AccomplishStringsList
    

    (not necessary to add the 'as AccomplishStringsList' - it is just a name for the results)