就我对DDD的理解而言,值对象只是对实体进行分区的一种方式.如果值对象应该与数据库中的ID一起存储,那么它不是值对象.
例:
域模型看起来像这样(C#):
public class Customer : Entity { public Guid CustomerID { get; } public string LastName { get; set; } public Address HomeAddress { get; set; } } public class Address : ValueObject { public string Street { get; set; } public string City { get; set; } public string ZipCode { get; set; } }
CREATE TABLE Customers ( CustomerID,LastName,HomeAddress_Street,HomeAddress_City,HomeAddress_ZipCode,)
要将地址存储在单独的表中,您将使其成为具有ID的实体.