1

假设以下场景(使用关系数据库),

class Currency
{
long id;
String code;
String name;
}

class OrderGroup
{
long id;
Collection<Order> Orders;
}

class Order
{
long id;
long currency;
}

在实际场景中,会有大量订单(数量不断增加)。将其转换为支持基于文档的数据库的最佳方法是什么?有一个更改货币代码和名称的选项,如果将货币添加为订单的子项,它会在所有订单中自动更新吗?

4

1 回答 1

2

在文档数据库中建模关系数据库时,如果您考虑 DDD 术语“聚合”并考虑如何处理更改对象的值,例如对象是Enitty 或 Value Object,那么在这种情况下,如果您如果希望货币的更改影响现有订单,货币不是价值对象,您只需引用 Order 中使用的货币对象,有点像关系模型。像这样建模它可以在 RavenDb 中工作:

OrderGroup 聚合:

public class OrderGroup
{
    public int Id { get; set; }
    public IList<Order> Orders { get; set; }
}

public class Order
{
    public int Id { get; set; }
    public int Currency { get; set; }
}

货币实体:

public class Currency 
{
    public int Id { get; set; }
    public string Code { get; set; }
    public string Name { get; set; }
}

但是请注意,像这样建模它需要单独的查询来获取/更新相关对象。

于 2011-10-10T08:42:07.923 回答