RavdnDb 自动索引

RavdnDb auto index

我在 RavdnDb 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; }
}

如何使用 ActiveApp 模型的 FirstName、LastName、UserName 索引 AppUser 模型的 PhoneNumber 属性?

我尝试使用此代码但没有成功:

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
                       };
    }

并尝试使用此查询:

    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'

RavenDb 创建的自动索引行之有效。

如何在 RavenDb 上查看生成的自动索引代码

不再有自动索引的代码。 试试这个模式:

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