nosqlravendbravendb-studio

RavdnDb auto index


I Have this models in RavdnDb version 4.0:

public class AppUser
{
    public AppUser()
    {
        ActiveInApps = new Dictionary<string, ActiveApp>();
    }
    public string Id { get; set; }
    public string PhoneNumber { get; set; }
    public Dictionary<string, ActiveApp> ActiveInApps { get; set; }
}

public class ActiveApp
{
    public bool IsActive { get; set; } = true;
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [JsonIgnore]
    public string DisplayName => $"{FirstName} {LastName}";
    public DateTimeOffset LastActivity { get; set; }
}

How can I Index PhoneNumber property of AppUser model with FirstName, LastName, UserName of ActiveApp model?

I tried with this code but didn't work:

public AppUser_ByModel()
    {
        Map = users => from u in users
                       let p = u.ActiveInApps.Values.FirstOrDefault(aia => aia.IsActive == true)
                       select new Model
                       {
                           PhoneNumber = u.PhoneNumber,
                           Id = u.Id,
                           FirstName = p.FirstName,
                           LastName = p.LastName,
                           IsActive = p.IsActive
                       };
    }

And tried with this query:

    from AppUsers  as user
         where user.PhoneNumber > '92' 
              or user.ActiveInApps[].FirstName = 'test'
              or user.ActiveInApps[].LastName = 'test'
              or user.ActiveInApps[].UserName = 'test'
              or user.ActiveInApps[].SerialNumber = 'test'
              or user.ActiveInApps[].LastActivity = 'test'

and RavenDb create auto index thats works.

How can I see the generated code for auto index, on RavenDb?


Solution

  • There is no code for automatic indexes any longer. Try this mode:

           let p = u.ActiveInApps.Select(x=>x.Value).FirstOrDefault(aia => aia.IsActive == true)