Ravendb 我可以在转换中使用上述方法而不是映射吗?索引是冗余存储。最好的数据来源是文档。预测不需要TransformResults。我知道,这些文档需要更好的例子。请记住,映射定义了索引的内容,当您以最终一致的方式存储文档时,就会发生这种情况。保存文档时,它是完全酸

Ravendb 我可以在转换中使用上述方法而不是映射吗?索引是冗余存储。最好的数据来源是文档。预测不需要TransformResults。我知道,这些文档需要更好的例子。请记住,映射定义了索引的内容,当您以最终一致的方式存储文档时,就会发生这种情况。保存文档时,它是完全酸,ravendb,Ravendb,我可以在转换中使用上述方法而不是映射吗?索引是冗余存储。最好的数据来源是文档。预测不需要TransformResults。我知道,这些文档需要更好的例子。请记住,映射定义了索引的内容,当您以最终一致的方式存储文档时,就会发生这种情况。保存文档时,它是完全酸性的(加载总是优先于查询)。TransformResults是在运行时查询索引时发生的,因此它是效率最低的选项。我知道TransformResults在处理方面是效率最低的选项,但在存储方面不是效率最高的选项吗?i、 e.如果我想让一组文档挂起


我可以在转换中使用上述方法而不是映射吗?索引是冗余存储。最好的数据来源是文档。预测不需要TransformResults。我知道,这些文档需要更好的例子。请记住,映射定义了索引的内容,当您以最终一致的方式存储文档时,就会发生这种情况。保存文档时,它是完全酸性的(加载总是优先于查询)。TransformResults是在运行时查询索引时发生的,因此它是效率最低的选项。我知道TransformResults在处理方面是效率最低的选项,但在存储方面不是效率最高的选项吗?i、 e.如果我想让一组文档挂起大量不同的读取模型,并且我希望支付处理成本(而不是存储成本),那么使用最少的映射创建这些索引并使用TransformResults在运行时进行投影不是更好吗?(类似于SQL术语中的视图概念)。非常感谢Matt。如果我需要在所有索引中将可空枚举作为字符串处理,那么处理可空枚举似乎相当麻烦。也许有必要重新思考我在域模型的许多领域考虑的字典方法。我通常选择具有特定定义的零值的枚举,例如空、无或默认值。另一方面,索引的关键目的是提供一个在视图中使用的读取模型(la CQRS)。我在想,使用最小映射和TransformResult的简单索引将更高效地存储,因为它不需要冗余存储投影数据。如您所说,如果文档是用于投影的数据源,那么我可以在转换中使用上述方法而不是映射吗?索引是冗余存储。最好的数据来源是文档。预测不需要TransformResults。我知道,这些文档需要更好的例子。请记住,映射定义了索引的内容,当您以最终一致的方式存储文档时,就会发生这种情况。保存文档时,它是完全酸性的(加载总是优先于查询)。TransformResults是在运行时查询索引时发生的,因此它是效率最低的选项。我知道TransformResults在处理方面是效率最低的选项,但在存储方面不是效率最高的选项吗?i、 e.如果我想让一组文档挂起大量不同的读取模型,并且我希望支付处理成本(而不是存储成本),那么使用最少的映射创建这些索引并使用TransformResults在运行时进行投影不是更好吗?(类似于SQL术语中的视图概念)。
    public class Product
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public SpecialType? DefaultOffer { get; set; }
        public Dictionary<SpecialType, string> Specials { get; set; }
    }

    public enum SpecialType
    {
        Something1,
        Something2
    }
    public class ProductSummary
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string SpecialOffer { get; set; }
    }
    public class ProductSummaries : AbstractIndexCreationTask<Product>
    {
        public ProductSummaries()
        {
            Map = products => from p in products
                              select new { p.Id, p.Name, p.DefaultOffer, p.Specials };

            TransformResults = (db, products) =>
                                from p in products
                                select new
                                {
                                    Id = p.Id,
                                    Name = p.Name,
                                    SpecialOffer = p.Specials[p.DefaultOffer.Value]
                                };
        }
    }
    [TestMethod]
    public void CanIndexIntoDictionary()
    {
        using (var documentStore = this.GetDocumentStore())
        {
            documentStore.ExecuteIndex(new ProductSummaries());

            // Store some documents
            using (var session = documentStore.OpenSession())
            {
                session.Store(new Product 
                { 
                    Id = "products/2", 
                    Name = "B", 
                    Specials = new Dictionary<SpecialType, string> 
                    { 
                        { SpecialType.Something1, "B1" }, 
                        { SpecialType.Something2, "B2" } 
                    }, 
                    DefaultOffer = SpecialType.Something2 
                 });
                 session.SaveChanges();
            }

            // Make sure it got persisted correctly
            using (var session = documentStore.OpenSession())
            {
                var b = session.Load<Product>("products/2");
                Assert.AreEqual("B2", b.Specials[b.DefaultOffer.Value]); // PASSES
            }

            // Now query and transform
            using (var session = documentStore.OpenSession())
            {
                var result = session.Query<Product, ProductSummaries>()
                    .Customize(x => x.WaitForNonStaleResults())
                    .AsProjection<ProductSummary>()
                    .ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("B2", result.First().SpecialOffer); // FAILS - actual is NULL
            }
        }
    }
    public enum SpecialType
    {
        None = 0,
        Something1,
        Something2
    }

    public class Product
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public SpecialType DefaultOffer { get; set; }
        public Dictionary<SpecialType, string> Specials { get; set; }
    }

    public class ProductSummaries : AbstractIndexCreationTask<Product,ProductSummary>
    {
        public ProductSummaries()
        {
            Map = products => from p in products
                              select new { p.Name, SpecialOffer = p.Specials[p.DefaultOffer] };

            Store(x => x.SpecialOffer, FieldStorage.Yes);
        }
    }
public class ProductSummaries : AbstractIndexCreationTask<Product, ProductSummary>
{
    public ProductSummaries()
    {
        Map = products => from p in products
                          let defaultOffer = AsDocument(p).Value<string>("DefaultOffer")
                          select new
                          {
                              SpecialOffer = defaultOffer == null ? null : AsDocument(p.Specials)[defaultOffer]
                          };

        Store(x => x.SpecialOffer, FieldStorage.Yes);
    }
}