RavdnDb自动索引

时间:2018-05-29 07:20:22

标签: nosql ravendb ravendb-studio

我在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上看到自动索引的生成代码

1 个答案:

答案 0 :(得分:0)

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

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