257
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
easily optimized, because you get a UNION ALL SQL statement back from EF. Having the same
domain model for relational databases or NoSQL
databases is not simple, and you should not try to
do it. You really have to design your model with an understanding of how the data is going to be
used in each particular database.
A benefit when using NoSQL databases is that the entities are more denormalized, so you do not set a
table mapping. Your domain model can be more flexible than when using a relational database.
When you design your domain model based on aggregates, moving to NoSQL
and document-
oriented databases might be even easier than using a relational database, because the aggregates
you design are similar to serialized documents in a document-oriented database. Then you can
include in those “bags” all the information you might need for that aggregate.
For instance, the following JSON code is a sample implementation of an order aggregate when using
a document-oriented database. It is similar to the order aggregate we implemented in the
eShopOnContainers sample, but without using EF Core underneath.
{
"id"
:
"2024001"
,
"orderDate"
:
"2/25/2024"
,
"buyerId"
:
"1234567"
,
"address"
:
[
{
"street"
:
"100 One Microsoft Way"
,
"city"
:
"Redmond"
,
"state"
:
"WA"
,
"zip"
:
"98052"
,
"country"
:
"U.S."
}
]
,
"orderItems"
:
[
{
"id"
:
20240011
,
"productId"
:
"123456"
,
"productName"
:
".NET T-Shirt"
,
"unitPrice"
:
25
,
"units"
:
2
,
"discount"
:
0
}
,
{
"id"
:
20240012
,
"productId"
:
"123457"
,
"productName"
:
".NET Mug"
,
"unitPrice"
:
15
,
"units"
:
1
,
"discount"
:
0
}
]
}
Dostları ilə paylaş: