【问题标题】:Cannot Index on array of int RavenDB无法在 int RavenDB 数组上建立索引
【发布时间】:2017-07-06 11:06:27
【问题描述】:

我正在尝试查询 IEnumerable int 类型的属性,以查找集合中包含此属性中的整数值的所有文档。

我试图通过属性上的索引来完成此操作,以返回满足查询的 id 列表。我在查询中投影 id,但是我得到了 id 0 的列表。

索引

public class Merchants_CategoryId : AbstractIndexCreationTask<Merchant>
{
    public class Result
    {
        public int MerchantId { get; set; }
        public IEnumerable<int> CategoryIds { get; set; }
    }

    public Merchants_CategoryId()
    {
        Map = merchants => merchants.Select(merchant => new
        {
            CategoryIds = merchant.Header.CategoryIds,
            MerchantId = merchant.Header.Id
        });
    }
}

查询

return await session
                .Query<Merchants_CategoryId.Result, Merchants_CategoryId>()
                .Where(x => x.CategoryIds.Any(c => c == categoryId))
                .Select(x => x.MerchantId)
                .ToListAsync();

【问题讨论】:

    标签: c# indexing ravendb


    【解决方案1】:

    索引:

    public class Merchants_CategoryId : AbstractIndexCreationTask<Merchant>
    {
          public class Result
          {
              public int MerchantId { get; set; }
              public int CategoryId { get; set; }
          }
    
    
          Map = merchants => from merchant in merchants
                             from categoryId in merchant.Header.CategoryIds
                             select new
                             {
                                 MerchantId = merchant.Header.Id,
                                 CategoryId = categoryId 
                             };
    
          Index(x => x.CategoryId, FieldIndexing.Yes);
          Store(x => x.MerchantId, FieldStorage.Yes);
    }
    

    查询:

    return await session
                .Query<Merchants_CategoryId.Result, Merchants_CategoryId>()
                .Where(x => x.CategoryId == categoryId)
                .Select(x => x.MerchantId)
                .ToListAsync();
    

    【讨论】:

    • 这仍然返回一个包含 0 个商家 ID 的列表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多