Let's do Some DDD With Entity Framework Core 3!
Let's get a handle on DDD Entity Framework!
Join the DZone community and get the full member experience.Join For Free
Now, we have full support for very cool stuff like C# 8, Async Enumerables, plus a brand new LINQ provider.
I’ve been using a lot of Entity Framework in my daily job, but of course, before upgrading a project ‘s dependency to a major version, there’s always some testing to do. As I often do, I decided to write a small demo and try out some of these new functionalities. You can find all the sources on GitHub.
My goal for this project was to model a bunch of Aggregates and Value Objects with proper Persistence Ignorance (e.g. I don’t want to pollute my business logic classes with code responsible for storing and retrieving data.
You may also like: How to Configure Entity Framework Caching.
Luckily, Entity Framework Core offers the possibility to configure the Entity/Table mapping using a nice Fluent Interface, avoiding attributes on our properties.
We have basically two options. The first one is to write all the configuration code in the OnModelCreating() method of our
DbContext. It's quick and easy, but it leads to a lot of very confusing code.
A much cleaner option is to use the database diagram generated with https://sqldbm.com:
- Create some products.
- Add just one product to a quote and save it.
- Update the quote adding another product.
- Create an order from that quote.
- Add another product to the quote.
- Create another order from the quote.
In the next post, we’re going to take a look at the code and talk about each Entity configuration. Stay tuned!
Published at DZone with permission of David Guida. See the original article here.
Opinions expressed by DZone contributors are their own.