How to deal with value objects in Entity Framework?

前端 未结 3 1176
灰色年华
灰色年华 2020-12-30 01:49

How do I persist value objects in Entity Framework without polluting my domain model? EF (well, relational DBs in general) require me to define a key - which my value object

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 01:52

    Vaughn Vernon writes about Persisting Value Objects (page 248) in his excellent book Implementing Domain-Driven Design.

    ORM and Single Value Objects

    The basic idea is to store each of the attributes of the Value in separate columns of the row where its parent Entity is stored. Said another way, a single Value Object is denormalized into its parent Entity's row. There are advantages to employing convention for column naming to clearly identity and standardize the way serialized objects are named.

    ORM and Many Values Backed by a Database Entity

    A very straightforward approach to persisting a collection of Value instances using an ORM and a relational database is to treat the Value type as an entity in the data model. (...) To accomplish this we can employ a Layer Supertype.

    Sample bounded contexts in C# can be found here: https://github.com/VaughnVernon/IDDD_Samples_NET

提交回复
热议问题