Here Is the Most Powerful EF Core Configuration Technique

preview_player
Показать описание
We only apply a handful of principles when configuring Entity Framework Core to persist a complex domain model: Property mapping, value conversions, complex types mapping, and the like. Out of these, value conversions are often overlooked.
Yet, value conversions are by far the most helpful technique that you can use to map domain models of great complexity into only a few tables and columns.
This video demonstrates the immense power value conversions have on simplifying the database schema and leaving the domain model isolated from it.

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
Рекомендации по теме
Комментарии
Автор

Im amazed. I dont know exactly what detail but somehow this video seemed like a massive upgrade in production quality. Careful now. We might start to expect this from you from now on.

elraito
Автор

🤯🤯🤯🤯🤯 okay you win. I'll join the Patreon.

jordanfarr
Автор

Hello Zoran! I have started watching your videos recently trying to expand my C# knowledge and they are an absolute goldmine. Thank you very much for producing content of this quality, showcasing this high of a skill level while still being easy to follow and learn from!

amakazor
Автор

Your lessons are all wonderful to me! You seem to be the Nicola Tesla of C#. живјели!

Tesfamichael.G
Автор

Glad you take this topic on the table, i also asked many times.
I personaly had to use .HasConversion but from diffrent reason, i have a problem with consistent interpretation of datetime type, because sql type has no timezone info or even
source info like DateTime in C# has, so i added conversion wich stored datetime as UTC always in database and EF done whole job.
Value conversion are nice, but sometimes they make reporting from external tools harder (because there is no dictionary or mapping in database).

AK-vxdy
Автор

I simply love I’m not alone loving EF Core. Thanks for this video and congratulations!

Gonzo
Автор

This is awesome. You split my head open far too often!

handlez
Автор

Great content, loved the convertion of PublicationDate to int

shmupful
Автор

Another great video and also some good laughs. I never knew we could do value conversions, I'm going to have to try this in my next project. Thank you :)

cmdr_thrudd
Автор

Excellent approach, I will try to implement it in my projects.

adiazwise
Автор

Amazing as usual. This is top tier content.

ElOroDelTigre
Автор

Indeed a good technique. Well done, Zoran!

AndersBaumann
Автор

Great video! It would also be very interesting to hear more about owned types and discriminations to have even more decoupled models and entities. Also how to best map immutable types / lists to support functional design

JonasMotiejauskas
Автор

I think it all depends which side you wanna be. The pure and "clean" domain models with "no" knowledge how it persists so far, but you have those complexities of transform to data/persistent models and converters.
Or you could simply use data models (anemic domain models) in CRUD nature style without complexities.
Which one to choose? It depends of which type of domain problems you are solving and complexity of the behaviors of your system.

Great videos btw. Congrats 🙏

haraheiquedossantos
Автор

Ok i have to look more carefully into this topic. It feels like the last piece I need to really go into a more organized approach and build the code in terms of what the application does instead of everything going around how the data will be stored in DB, which has been a problem multiple times as the app evolves.
Very interesting

Jojor
Автор

Absolutely loved the video. My key take away is that proper design upfront makes for a pleasant development experience later.
I lazily relied on C# Tooling to create migrations and stuff for me which works nice but makes integrating proper Design more complicated because you need DTOs. This approach forces to actually learn EF Core deeply and use it properly. Thanks for sharing.
Its time to study EF Core in more detail.

Quick question. How did you do that SQL Query in VSCode?

plgueis
Автор

Excellent video as always Zoran.

Yet, I do find parts of this implementatiom a little bit lacking in your usual elegance.
I don't mean that as a critcism in any way - I certainly could not do it better - but there's a few observations which I think are worth making.

Firstly, the pairing of EditionToString and StringToEdition struck me as potentially problematic.
As it stands, when there are only two implementations of IEdition, it is fine.
However, if there were more implementations, and you had to account for every one inside both switch statements - where each is exactly the inverse of the other - this seems like a recipe for bugs - where one type is inadvertently serialized/de-serialized as another.

Secondly, the private property "PublicationKind".
In the Configuration class, you are concerning yourself with setting the value of a private field.
Under normal circumstances, you wouldn't ever do this - but you need to do it here - and worse, you use a magic stiring representing the property name to do so.
This feels like we're breaking one of the cardinal rules of OOP here.

The conversion of PublicationDate to/from an int is also a bit confusing.
If the opposite of this rich-domain model is using simple primitive types - persistance is easy.
DateTime in C# world maps to DateTime/DateTime2 in SQL world.
Whereas here, we have to come up with an elaborate multiplication/division system just to ensure we get the correct type.


Again, another superb video, but I think the commenters at the beginning of the video have a valid point. Persisting this is tricky.

conbag
Автор

Great Video! It inspired me to try adding a MailAddress ValueConversion to a project I'm currently working on but I had to bail once as I realised I would no longer be able to query email addresses by host.

Using the CultureInfo example, lets say we have book cultures fr, en-GB, en-US. Now we just want to retrieve all english (en) books.

Previously this could have been achieved with books.Where(book => I am pretty sure books.Where(book => == "en") is going to throw.

Using custom value conversion will limit your ability to query these fields with EF.

peterriesz
Автор

hey zoran! thx for the video as always :) in any of your entities i see fk, why is that? do u use shadow props?

Buutyful
Автор

Excellent approach! I am tired of looking at Clean architecture tutorials which advise you to abstract EF by creating custom IRepository and IUnitOfWork. EF Core has such a wonderful feature to map domain models to db. Why nobody uses it?

dobripopov