在Orders和OrderLines的经典案例中,每个OrderLine都有对其父订单的引用。当我将OrderLine保存到RavenDB时,它会将完整订单记录的副本保存为每个OrderLine的属性。如何让它仅保存订单的链接?像这样:
{
...other orderline properties...
Order : "orders/123"
}
而不是
{
...other orderline properties...
Order : {
...all properties for order 123...
}
}
答案 0 :(得分:3)
欢迎使用非关系型数据库!订单行不会获得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。