ravendb - 存储对父文档的引用而不是存储文档的副本

标签 ravendb

在订单和订单行的经典案例中,每个订单行都有对其父订单的引用。当我将 OrderLine 保存到 RavenDB 时,它会将完整订单记录的副本保存为每个 OrderLine 的属性。如何让它只保存订单链接?像这样:

{ 
...other orderline properties...
Order : "orders/123"
}

而不是这个

     {
        ...other orderline properties...
        Order : {
    ...all properties for order 123...
        }
}

最佳答案

欢迎使用非关系数据库!订单行没有 ID。他们不会被放入自己的文档中。它们存储在重要的地方 - 与订单一起!

public class OrderLine
{
    public string Product { get; set; }
    public int Quantity { get; set; }
    public decimal Price { get; set; }
}

public class Order
{
    public string Id { get; set; }
    public string CustomerId { get; set; }
    public List<OrderLine> Lines { get; set; }
    public decimal Total { get; set; }
}

生成如下文档:

orders/123
{
    "CustomerId": "customers/456",
    "Lines": [
        { "Product": "Foo", "Quantity": 2, "Price": 10.00 },
        { "Product": "Bar", "Quantity": 3, "Price": 20.00 },
        { "Product": "Baz", "Quantity": 4, "Price": 30.00 }
    ]
    "Total": 200.00
}

请参阅 the documentation 了解更多信息。

关于ravendb - 存储对父文档的引用而不是存储文档的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15209310/

相关文章:

c# - 具有不同 LINQ 语法的 Raven Db 似乎无法正常工作

full-text-search - ravendb 结合 Search 和 Where

c# - 如何在 C# 中连接到 RavenHQ

c# - 刚刚将 RavenDB 更新为 rev。 2230 从转。 960 和调用 session.SaveChanges() 我有 JsonSerialization 异常

c# - RavenDB 索引 : Need a solution to merge 2 dictionary fields into a single dictionary, 将其展平并使其可搜索

c# - 用于嵌套查询的 RavenDB 索引

RavenDB 轮询的替代方案(推送通知)

ravendb - 使用客户端 api 在 ravendb 中解决 selectmany

c# - 使用 RavenDB 时,我应该把业务逻辑放在哪里

c# - 如何在 RavenDB 中查询包含指定类型的嵌套对象的文档