Edition 0 Updated to asp. Net core 0



Yüklə 11,82 Mb.
Pdf görüntüsü
səhifə224/288
tarix12.07.2023
ölçüsü11,82 Mb.
#136458
1   ...   220   221   222   223   224   225   226   227   ...   288
NET-Microservices-Architecture-for-Containerized-NET-Applications

Additional resources 

Table Mapping
https://learn.microsoft.com/ef/core/modeling/relational/tables
 

Use HiLo to generate keys with Entity Framework Core
https://www.talkingdotnet.com/use-hilo-to-generate-keys-with-entity-framework-core/
 

Backing Fields
https://learn.microsoft.com/ef/core/modeling/backing-field
 

Steve Smith. Encapsulated Collections in Entity Framework Core
https://ardalis.com/encapsulated-collections-in-entity-framework-core
 

Shadow Properties
https://learn.microsoft.com/ef/core/modeling/shadow-properties
 

The Specification pattern
https://deviq.com/specification-pattern/
 
Ardalis.Specification NuGet Package
Used by eShopOnWeb. 
 
https://www.nuget.org/packages/Ardalis.Specification
 
Use NoSQL databases as a persistence infrastructure 
When you use NoSQL databases for your infrastructure data tier, you typically do not use an ORM like 
Entity Framework Core. Instead you use the API provided by the NoSQL engine, such as Azure Cosmos 
DB, MongoDB, Cassandra, RavenDB, CouchDB, or Azure Storage Tables. 
However, when you use a NoSQL database, especially a document-oriented database like Azure 
Cosmos DB, CouchDB, or RavenDB, the way you design your model with DDD aggregates is partially 
similar to how you can do it in EF Core, in regards to the identification of aggregate roots, child entity 
classes, and value object classes. But, ultimately, the database selection will impact in your design. 
When you use a document-oriented database, you implement an aggregate as a single document, 
serialized in JSON or another format. However, the use of the database is transparent from a domain 
model code point of view. When using a NoSQL database, you still are using entity classes and 
aggregate root classes, but with more flexibility than when using EF Core because the persistence is 
not relational. 
The difference is in how you persist that model. If you implemented your domain model based on 
POCO entity classes, agnostic to the infrastructure persistence, it might look like you could move to a 
different persistence infrastructure, even from relational to NoSQL. However, that should not be your 
goal. There are always constraints and trade-offs in the different database technologies, so you will 
not be able to have the same model for relational or NoSQL databases. Changing persistence models 
is not a trivial task, because transactions and persistence operations will be very different. 
For example, in a document-oriented database, it is okay for an aggregate root to have multiple child 
collection properties. In a relational database, querying multiple child collection properties is not 


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
}
]
}

Yüklə 11,82 Mb.

Dostları ilə paylaş:
1   ...   220   221   222   223   224   225   226   227   ...   288




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin