According to Microsoft (https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-implemenation-entity-framework-core) to encapsulate domain behavior private properties and readonly collections like this:
private readonly List<OrderItem> _orderItems;
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
And you can get the order with encapsulated order items like this:
public async Task<Order> GetAsync(int orderId)
{
var order= await _context.Orders.FindAsync(orderId);
if (order != null)
{
await _context.Entry(order)
.Collection(i => i.OrderItems)
.LoadAsync();
}
return order;
}
But what if the order items itself have encapsulated lists like following tree:
Supplier -> Catalogs -> CatalogItems
How do I get the CatalogItems collection as well?
Include/ThenInclude? There is nothing DDD specific. - Ivan Stoev