Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to Query RavenDB Entity with a Collection via Index
    text
    copied!<p>I have a RavenDB mvc applicaton that has a document entity called Member. Each Member document has a list of users that are considered administrators. Only they can view and manage that Member document. On one of the pages I have a member search and have created an index to assist in the search.</p> <pre><code>public class Members_ByName : AbstractIndexCreationTask&lt;Member&gt; { public Members_ByName() { Map = members =&gt; from member in members select new {member.Title}; Indexes.Add(x =&gt; x.Title, FieldIndexing.Analyzed); Sort(x =&gt; x.Title, SortOptions.String); } } public class UserReference { public string Id { get; set; } public string Name { get; set; } } public class Member { public string Id { get; set; } public string Title { get; set; } public ICollection&lt;UserReference&gt; Administrators { get; set; } } </code></pre> <p>Since the user can only view/manage Member documents where they are an Administrator when I do the following to get the members </p> <pre><code>RavenQueryStatistics stats; var query = RavenSession.Query&lt;Member, Members_ByName&gt;().Statistics(out stats); query = query.Where(x =&gt; x.Title.StartsWith("anything")); query = query.Where(x =&gt; x.Administrators.Any(y =&gt; y.Id == CurrentUser.Id)); var list = query.OrderBy(x =&gt; x.Title).Paging(CurrentPage, Configuration.DefaultPage, CurrentPageSize).ToList(); </code></pre> <p>When the above code runs I get "The field 'Administrators_Id' is not indexed, cannot query on fields that are not indexed" which I understand but every thing I have attempted to get Administrator's Id in the index has not worked and not sure how to make it work at this point.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload