Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@sergbo3114
4 ай бұрын
What about Aggregate root mapping in this case?
@davearkley7014
Жыл бұрын
Another great video, really useful. A few thoughts though.... Your property on Customer is called Email, but it's an EmailAddress. Small bugbear since I have a customer who store entire Emails in their database, and since they don't archive it's TB of data. Also according to RFC 5321, which defines the Simple Mail Transfer Protocol (SMTP), the maximum length of an email address is 320 characters. This includes both the local part and the domain part, as well as the '@' symbol that separates them. However, RFC 5321 also recommends that email addresses should be no longer than 64 characters for the local part and 255 characters for the domain part, as these are the limits imposed by the most commonly used email systems. Therefore, while the maximum length of an email address according to the RFC is 320 characters, it is generally advisable to limit email addresses to 64 characters for the local part and 255 characters for the domain part.
@MilanJovanovicTech
Жыл бұрын
Very valid point there 😁
@okcharles7
8 ай бұрын
Wow. I can't understand why the algorithm has attracted me to this video just now, which was the subject I were heavily searching. I have been using configurations just as a supportive role to mapping conventions on entity classes, which means I have always been defining entity classes and domain classes separately. Your video shows how to effectively use them with less maintenance points. Thanks for great work.
@MilanJovanovicTech
8 ай бұрын
Maybe because you were heavily researching 😁 In any case, glad the video was helpful
@timurrozhok2685
11 ай бұрын
I find this tutorial very comprehensive, since the narration escalates from simple examples to most complicated ones. Alternative approaches are also pointed out. And yet it's very easy to watch. 'Q' stands for "Quality", and 'A' stands for "Awesome"! :) By the way, I guess some read-only wrapper collection is knocking in the door in case of that 'LineItems' property. Perhaps even with a lazy initialization of the wrapper. But that's just details :)
@MilanJovanovicTech
11 ай бұрын
Glad you liked the video :) A readonly wrapper is an interesting twist. 😁
@timurrozhok2685
11 ай бұрын
@@MilanJovanovicTech Yeah, my notion was quite obvious 😄 But anyway, I meant not to create a new list on each getter call.
@gianlucalocri
Жыл бұрын
Your videos are pure shining gold! Thank you Milan!
@MilanJovanovicTech
Жыл бұрын
Wow, thank you!
@MehediHasan-xd6rj
5 ай бұрын
Whenever I am learning new things in C#, I always try to verify how Milan does it. Thank you for these nice videos.
@MilanJovanovicTech
5 ай бұрын
Happy to help!
@anilkarasahh
Жыл бұрын
I have always wondered how the EF Core maps value objects to the databases, never had time to look up, though. Everything I learn about EF always feel magical. Such a great companion! Thank you for this nice video, Milan!
@MilanJovanovicTech
Жыл бұрын
Just additional columns in this case, and for OwnsMany it's a separate table
@MarcusKaseder
Жыл бұрын
You can also specify how to map owned properties. For example, price can be mapped to a separate table. But it makes no sense for most cases.
@pilotboba
Жыл бұрын
@@MarcusKaseder Yep, you can also map it as JSON.
@ahmedmostafa-zu5kr
Жыл бұрын
actually, It's my first time posting a comment under a youtube video. But I really enjoyed your way of simplifying topics
@MilanJovanovicTech
Жыл бұрын
I appreciate that!
@dandoescode
Жыл бұрын
After configuring the Order and LineItem configuration as you've shown, I am getting an EF error when trying to create an order and save it to the Database. Unable to cast object of type 'System.Collections.Generic.HashSet`1[DDD.Domain.Orders.LineItem]' to type 'System.Collections.Generic.IReadOnlyList`1[DDD.Domain.Orders.LineItem]' Is there additional configuration needed?
@MilanJovanovicTech
Жыл бұрын
Switch the HashSet for a List
@dandoescode
Жыл бұрын
@@MilanJovanovicTech that did the trick. Thanks! Loving the DDD related videos. 😄
@aweklin
Жыл бұрын
Hi Milan, Thanks a million for all the great work on this channel. You are indeed a great role model. I love the way you organize your tutorial series. But I want to plead with you to kindly add this order management series to a playlist to make it easy to follow through instead of searching which come next. Thanks
@MilanJovanovicTech
Жыл бұрын
All right, I'll work on that 😅
@joga_bonito_aro
Жыл бұрын
Great video as always. One thing I would add is a base class/record for StronglyTypedIds. It would make your life easier in the long run when using generics/interfaces for strongly typed IDs. You could also create a generic StronglyTypedId converter for EF Core.
@MilanJovanovicTech
Жыл бұрын
Good point, I'll see if I can do that in another video
@adiviuh3693
Жыл бұрын
@@MilanJovanovicTech Hello again) After your video about STIDs I've researched this topic and implemented it in my pet project. There are some ready technic for working with this feature. You can find them wonderful to research. You can find ready code for ef converters, so you will need to use only builder.HasKey method and builder.Property for telling ef core that props are existing. And other features, like json converters default and newtonsoft. Also there is one big problem, that could be solved using a source generator (at least I found it in article), for ToString method. So, good lack into self-improvement.
@adiviuh3693
Жыл бұрын
I have another question. I think you have not touched the issue with constructors in EF core context. I think they are the most problematic things. So, you need to show people, how to create them. What exactly they could have in case of ef mappings. Why you have to create an additional ctor for ef in some cases, for example then you have a navigation property in ctor. How to work with get only props... Answers on this questions I've taken by pieces in internet and manual experiments. So it's important points in case of DDD. Sorry, for my English 😅
@adiviuh3693
Жыл бұрын
Last question. Do you plan to record videos about microservices and all that staff includes best practices and issues around them? I think it would be a great destination after DDD, clean code and etc. Microservices -> concurrency (at least it's general point of thinking about it, in my opinion). You are an amazing person. Thank you for your contribution. 💪
@mbsa220
Жыл бұрын
Perfect ! DDD and EFCore are such a great companion !
@MilanJovanovicTech
Жыл бұрын
The recent EF features made it all possible
@JesuMarquez
Жыл бұрын
Thank's for sharing! In your example you use EF but, which will be the approach using ADO?🤔
@MilanJovanovicTech
Жыл бұрын
ADO isn't an ORM
@bogdanashvets3260
Жыл бұрын
Milan, your channel is a treasure :)
@MilanJovanovicTech
Жыл бұрын
Thank you so much, Bogdana! :)
@tvardero
Жыл бұрын
Waiting for EF8 to use structs as value objects ) Great video!
@MilanJovanovicTech
Жыл бұрын
I think they have plans to use value converters, we'll see
@matthewrossee
Жыл бұрын
What if the value object can be nullable? When configuring conversion in ef core I get an error about using conditional access in an expression, e.g. builder.Property(x => x.SomeProperty).HasConversion(x => x?.Value, value is null ? null : SomeProperty.Create(value)); How do you approach this? Especially if this is a property with other aggregate's Id.
@MilanJovanovicTech
Жыл бұрын
Can it be nullable in DB? Then you need to support that. Either with Null object pattern or making it explicitly null with nullable reference types.
@gorannikolic5735
Жыл бұрын
Great video Milan, just one question, how you would set Max length of the SKU value in the Products table, and how you would create an index on it?
@MilanJovanovicTech
Жыл бұрын
I believe you can do something like Property(p => p.Sku).HasMaxLength or Property(p => p.Sku.Value).HasMaxLength Same approach for the index. I think the first one will work because of the define conversion.
@birukayalew3862
Жыл бұрын
Very awesome ❤ ... i can't wait the next video. Thank you Milan
@MilanJovanovicTech
Жыл бұрын
Next one will be controversial 😁
@birukayalew3862
Жыл бұрын
@@MilanJovanovicTech I guess it should be about repository pattern?
@theveloper3678
9 ай бұрын
Awesome Video Milan! 🎉🚀 Thanks for this series Did you miss configuring OrderId as fk on lineItem in the LineItemConfiguration on purpose ?
@MilanJovanovicTech
9 ай бұрын
EF can figure it out by convention most of the time
@Speede04
Жыл бұрын
I wish one time you show us how to configure many-to-many relationship in EF Core with intermediate table and additional data in it ( not for sorting, but for usage :) )
@MilanJovanovicTech
Жыл бұрын
Oh, for sure. I'll come up with a goof example first and include it in a future video
@furious385
8 ай бұрын
How did you do migration with two class lib project ??? if i will try to do something like that i will get error : Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time
@MilanJovanovicTech
8 ай бұрын
You can specify the target project for the migration
@dragannikolic568
Жыл бұрын
Hi Milan, I followed your instructions from the video on small exercise project as I want to improve my skills with your tutorials. Just watching is not enough ;) However, when I tried Add-Migration Create_Database in PMC, I got an error: No suitable constructor was found for entity type 'LineItem'. The following constructors had parameters that could not be bound to properties of the entity type: Cannot bind 'price' in 'LineItem(LineItemId id, OrderId orderId, ProductId productId, Money price)' Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound. I had to add empty constructor to LineItem class in order to fix the problem: internal LineItem() { } I am puzzled why this happens with EF and why it did not happen in your case. Please if you have time explain what happens, or someone else ca explain too. Note: I'm using .NET 7.0.4 libraries and sql server provider
@MilanJovanovicTech
Жыл бұрын
Add a private or internal default CTOR and you will be fine. Unfortunate, but you have to do that with EF Core
@dragannikolic568
Жыл бұрын
@@MilanJovanovicTech Thx!
@dandoescode
Жыл бұрын
I had the same problem. Thanks guys!
@MehediHasan-xd6rj
5 ай бұрын
I've faced the same problem. The LineItem's private constructor resolved the issue.
@Maskenken
2 ай бұрын
This is really nice. I'm getting CS8618 warnings about the strongly typed ids. It looks like you get the same squiggly lines under the private constructor in the domain. Did you remove this warning in editorconfig?
@MilanJovanovicTech
2 ай бұрын
Yeah, pretty pointless. We need the private ctor for EF, but it warns that some reference types aren't initialized.
@Maskenken
2 ай бұрын
@@MilanJovanovicTech Thank you. I'm inspired by your approach to C# and teaching. My current project is based on your videos.
@hkoueke
Жыл бұрын
Right on time. Keep up Milan👍💪
@MilanJovanovicTech
Жыл бұрын
Thank you, hope it was practical 😁
@dalisaacs
Жыл бұрын
Hello Milan. Thanks for this awesome training. However i get an error when i run migration... CustomerId requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. Any idea what might be causing this?
@MilanJovanovicTech
Жыл бұрын
Did you miss something? Are you on .NET 7? 🤔
@dalisaacs
Жыл бұрын
@@MilanJovanovicTech The problem occurs if you don't map the foreign keys correctly of forget to do so. So that was what i did and it is now fix. Thanks.
@lara97196516
22 күн бұрын
Saludos amigo. Gracias por el contenido. Tengo una duda: al implementar directamente el dominio Customer en la capa de persistencia no estás violando el principio de arquitectura limpia? Infraestructura o persistencia no debería tener referencia con el dominio. Ayúdame aclarar ese tema por favor 🙏🏻
@MilanJovanovicTech
22 күн бұрын
"Infrastructure or persistence should have no reference to the domain." - They are allowed to reference the domain. How else would you build an application?
@microtech2448
Жыл бұрын
Hi, should our domain entities match exactly with Db tables/columns? If no, then would we end up creating similar/duplicate entities in persistence project?
@MilanJovanovicTech
Жыл бұрын
I don't think so (when you have a complex domain). I make my entities persistence ignorant, and take care of the mapping with EF
@microtech2448
Жыл бұрын
@@MilanJovanovicTech thanks
@ddreamz94
6 ай бұрын
Hey Milan and thanks for the content. I feel a little bit lost when i have to configure many-to-many relationships. Do you have any suggestions or something I can read in order to learn more how to handle them in the context of DDD? Thank you!
@MilanJovanovicTech
6 ай бұрын
The EF docs are a great start
@mihaiga
Жыл бұрын
Great video Milan. My only suggestion is related to ownership of Value Objects: you should not be able to manipulate value objects independent of the Root Aggregate which you can if the value objects have their own EF objects, independent of the root aggregate. If you need to guarantee atomicity when saving the whole aggregate, you could use OwnsMany or OwnsOne when defining the RA Configuration class to specify one:one or one:many relations. However, if a root aggregate has many value objects then the performance can be impacted by "cartesian explosion" scenarios, partially managed by query splitting.
@MilanJovanovicTech
Жыл бұрын
Where did I make value objects to their own objects? 🤔
@mihaiga
Жыл бұрын
@@MilanJovanovicTech You are right, in the video you don't do that. I wanted to add some extra info from my experience with modelling domain entities using EF.
@danielegiovanetti9258
Жыл бұрын
Super super super video! Very useful for me. Thanks
@MilanJovanovicTech
Жыл бұрын
Glad it was helpful!
@nawarali1998
10 ай бұрын
Great content Thanks for your effort. Assuming I have Categories will each product will have multiple categories and each category will contains multiple products which lead to many-to-many relationship my question is assuming I would like to define the Product as an Aggregate root also the Category how to break the relation between them using ef-core because we can't reference other aggreagets which lead to keeping only the ids of each one on the other end of the relationship?
@MilanJovanovicTech
10 ай бұрын
You can make exceptions to any rule. This would be one of them. And this looks more of a CRUD rule than a business rule.
@davittonoyan6537
Жыл бұрын
Hi Milan, how does EF creates object of "Order" when we try to get it from db? Because in order class there is private constructor and properties are private set, there is only create method.
@MilanJovanovicTech
Жыл бұрын
Using the private parameterless ctor that I added in the Order class
@davittonoyan6537
Жыл бұрын
@@MilanJovanovicTech yes but for example if you want to get orders from Db List orders = context.Orders.ToList(); in this case when EF Reads data from Db it should map it and create objects (Order) right? Do you mean that for th ORM mapping it uses Create method that you wrote in Order class?
@10199able
Жыл бұрын
You used class for Customer, Product, LineItem, Order, but record for Money, Sku (mb I missed something). Should you have used records for all of them? I remember there were some constraints on using records with ef.
@MilanJovanovicTech
Жыл бұрын
I'm using records where I want structural equality for Value Objects
@ibrahimfouad6927
Жыл бұрын
Good work keep going. But you can handle strongly typed ids with custom value converter to automatically apply conversion from and to database.
@MilanJovanovicTech
Жыл бұрын
You mean one custom converter for all strongly typed IDs?
@ibrahimfouad6927
Жыл бұрын
@@MilanJovanovicTech Yes exactly one custom generic value converter with base class/record for Strongly typed ids that handles all the conversion automatically. You will scan for all strongly typed id by their base then apply the value converter.
@GrimReaper160490
Жыл бұрын
Have you considered generating a course from this DDD series? Thanks for this Milan great stuff as usual :)
@MilanJovanovicTech
Жыл бұрын
Yes, it's going to happen. But I may not start with a DDD course straight away
@GrimReaper160490
Жыл бұрын
@@MilanJovanovicTech That's fair 😀 looking forward to it
@evilroxxx
9 ай бұрын
I have an abstract base class called Entity and have Order, OrderLine and Product derive from it. Now when I run migration it creates a single table called Entity with a type column that includes different values for Order, OrderLine and Product. Instead of this (which is wrong) how do I ensure my EF Core migration will create three tables for Order, OrderLine and Product? I tried this in .NET 5, 6 and 7. Haven't tried 8 yet but I am sure its the same. How to fix this?
@MilanJovanovicTech
9 ай бұрын
How did you configure the entities with EF?
@evilroxxx
9 ай бұрын
@@MilanJovanovicTech IEntityTypeConfiguration you mean? Using fluent API not using Annotations. Is this an issue? How do you normally do it?
@elpe21
Жыл бұрын
how would you control concurrency? :) would you just add LastModified / RowVersion to domain classes and via EF Core configuration set them as IsConcurrencyToken in EntityTypeConfiguration?
@MilanJovanovicTech
Жыл бұрын
I'd say make a tradeoff and simply use the EF concurrency control mechanism. It's one field in the domain, and maybe you can even make it a private field so it's not exposed.
@Tamer_Ali
Жыл бұрын
Awesome Milan, you always amazing me 👍 I hope you talk about object mapping using Mapster or AutoMapper Keep going
@MilanJovanovicTech
Жыл бұрын
Maybe Mapster? I'm not a fan of mapping libraries
@Tamer_Ali
Жыл бұрын
@@MilanJovanovicTech I'm using Mapster. what is the other way you use for mapping and its benefit over libraries? I hope you record a video for it
@pilotboba
Жыл бұрын
I'm coming to agree with those that say these using mappers are an anti-pattern. But, using Mapster with CodeGenration my be a happy medium.
@sachinshrestha2538
10 ай бұрын
why dont we have customer propery as navigation in the order entity i dont get it can we have it if want to
@MilanJovanovicTech
10 ай бұрын
You can for EF concerns. But DDD says you can't reference other aggregates directly. It will lead to a dirty domain model.
@kurtdeduytsche7558
11 ай бұрын
hi milan, great video. just visited your website and wanted to enroll for your clean architecture course, but i'm a poor student and a little too expensive for me. is there a coupon code available i can use so it would be less expensive for me. thanks in advance
@MilanJovanovicTech
11 ай бұрын
There's a Black Friday discount running right now
@prantobhoumik6586
10 ай бұрын
@@MilanJovanovicTech same ..I am also intern student. 150 dollar is very expensive for me residing at India. So can you please help me by giving any coupon or discount 🥺
@pabloferrando6471
Жыл бұрын
How would you work with enums, both at domain and EF Configurations? Just to provide an example, let’s say that an Order could be scheduled and have a periodic occurrence which could be expressed by having an Occurrence Value Object. This would be composed by a collection of DaysOfWeek (Monday, Tuesday, etc) and a Perioricity (Weekly, Biweekly, Monthly, etc). How would you store this without recurring to convert the collection into a comma separated string?
@MilanJovanovicTech
Жыл бұрын
Enumes can be stored as integers or strings
@pilotboba
Жыл бұрын
EF inherently supports enums. No specific conversion is needed.
@Ozarif
Жыл бұрын
Great video Milan, than you.
@MilanJovanovicTech
Жыл бұрын
You're welcome
@joga_bonito_aro
Жыл бұрын
Another topic that could be interesting. Mapping domain aggregates/entities to dto and back
@MilanJovanovicTech
Жыл бұрын
Usually EF Core takes care of that. Only becomes interesting if you have to do it manually.
@joga_bonito_aro
Жыл бұрын
@@MilanJovanovicTech which happens alot in my cases... maybe i'm doing it wrong >D
@arny6641
2 ай бұрын
Hi Milan, Thanks for the great video ! I’m wondering why not configure the LineItems with OwnsMany ? In my understanding, an Order should always be fetched with its Items, and a LineItem should not be directly fetched from the database. Am I wrong ?
@MilanJovanovicTech
2 ай бұрын
Owned entities behave strangely with EF Core, so I'd avoid it. We can configure AutoInclude for navigation properties.
@arny6641
2 ай бұрын
@@MilanJovanovicTech Never heard of AutoInclude before. Thank you for your answer and for teaching so many stuff
@nathansickle1916
Жыл бұрын
How do you handle serialization of strongly-typed IDs (using System.Text.Json or Newtonsoft, either one)? We can create custom converters; however, we would need one for every ID type and there may be many such types.
@MilanJovanovicTech
Жыл бұрын
You can either map back into ID, or create a simple flag interface and use a custom converter on that
@volodymyrliashenko1024
Жыл бұрын
Good, but I didn't get how EF will return an order with LineItems if it has only a getter. It should throw except, shouldn't it?
@MilanJovanovicTech
Жыл бұрын
It can fill in the backing field :)
@volodymyrliashenko1024
Жыл бұрын
@@MilanJovanovicTech I assume it is going to be implemented as setter. If yes, there is no sense to have a separate method to encapsulate adding items to the list. How are you going to make it work for EF?
@danielszopa4303
Жыл бұрын
It is very good video!!!! Keep delivering videos like this! I have one question, I do not want to query for all data from my entity, I want to get user entity without password and others PII data, so I use select method to get only data which I want, but my entity have business logic to defends the entity from creating instance without password, email etc.. Is there any way to deal with it or I need to create some readmodel to choose what I want during query?
@MilanJovanovicTech
Жыл бұрын
Yes - don't store any of that in the User entity to begin with. Better yet, use an external IDP
@harshaghanta1
Жыл бұрын
Hi Milan, For some reason I was getting an error while generating the Migration script. And ended up changing the LineItem class to have the constructors as below. public LineItem(LineItemId id, OrderId orderId, ProductId productId, Money price) : this(id, orderId, productId) { Price = price; } private LineItem(LineItemId id, OrderId orderId, ProductId productId) { Id = id; OrderId = orderId; ProductId = productId; }
@MilanJovanovicTech
Жыл бұрын
A private parameterless ctor usually works
@paisaconmaquina
8 ай бұрын
This comment solved my issue, I've spent all day with this. The error is: Cannot bind 'price' in 'LineItem(LineItemId id, OrderId orderId, ProductId productId, Money price)' I needed to replace the ctor for LineItem value object: from: internal LineItem(LineItemId id, OrderId orderId, ProductId productId, Money price) { Id = id; OrderId = orderId; ProductId = productId; Price = price; } to: what @harshaghanta1 commented. Do you know why does not work the initial ctor?
@alfredorodriguez598
Жыл бұрын
In the documentation there is an abstract class ValueObject, is it no longer necessary to inherit it to make the valueObjects?
@MilanJovanovicTech
Жыл бұрын
Which documentation?
@murat.yuceer
Жыл бұрын
Hi Milan, What if you have multiple money field in same entity but share same currency field Curreny, Amount, Fee (Amount and Fee is Money but must share same currency) How will you map thaT?
@MilanJovanovicTech
Жыл бұрын
Then you would duplicate the currency field, or create another object with multiple amounts and a single currency instance.
@murat.yuceer
Жыл бұрын
@@MilanJovanovicTech nice approach
@alpsavasdev
Жыл бұрын
Isn't it a simpler and more straightforward approach to map domain entities to database entities via mappers (or in a custom way)? You can have more control over the entity mappings and do not have to deal with the complexity of fluent api?
@MilanJovanovicTech
Жыл бұрын
I don't find the fluent API complex 🤷♂️
@alpsavasdev
Жыл бұрын
@@MilanJovanovicTech actually I also use fluent api and just asked about comparison to other approach out of curiosity because I haven’t yet tried mapping for data access myself. Thanks for your content, appreciate it 😎
@FranckMercado
Жыл бұрын
Good video. That's a nice feature of EF Core, although what if you need to change table schemas, database constraints or even another database? You end up limited by EF Core functionality and flexibility.
@adiviuh3693
Жыл бұрын
What do you mean? EF Core could be used with different databases, in general SQL like dbs. EF core also have ability to specify which db schema should be used for your DbContext class or even for your table (you can use second argument of the method ToTable() in EntityTypeBuilder. For example, builder.ToTables(”Cats”, schema: "zoo"); Right now EF Core has a very elegant interface for configuring your db and also has a great performance (than before). Of course these abstractions have some performance troubles, in this case you can use something like Dapper, but I think it has to be used only for specific tasks with requirements of high performance.
@FranckMercado
Жыл бұрын
@@adiviuh3693 It's fine that EF Core can provide such features, but the purpose of the comment is to depend on your own interfaces and not a specific library interface. If EF Core fits your needs that's alright but if it doesn't you will only find out late in the software life cycle as you will be tied to the library functionality, upgrades, bugs, etc. For small apps I'd say go for it but for bigger, complex ones it's best to depend on your own interfaces.
@MilanJovanovicTech
Жыл бұрын
You win some, you lose some. Right?
@Greenthum6
Жыл бұрын
Note that exposing a list as IReadOnlyList does not make the list immutable. The caller can cast it to IList or List and modify the contents freely. I think returning only the enumerator of the list could work as it can be used to create a new list, but not modify the original via it.
@MilanJovanovicTech
Жыл бұрын
I tried casting and it didn't really work as planned
@sinemedev7840
Жыл бұрын
The ToList() creates a shallow copy, so you are fine. Even if someone would take the LineItems and cast it back to List, adding to that list wouldn't affect the original _lineItems List which is used for the database. The proper way would be to use the AsReadOnly method instead of ToList, so public IReadOnlyList LineItems => _lineItems.AsReadOnly();
@isaacayodeji322
Жыл бұрын
this is sooooooo good
@MilanJovanovicTech
Жыл бұрын
I'm glad you enjoyed it!
@mahmoudhelalii4512
Жыл бұрын
great effort. Could you make a video about elastic search ?
@MilanJovanovicTech
Жыл бұрын
Will try
@microtech2448
Жыл бұрын
Can we use automapper for this task?
@MilanJovanovicTech
Жыл бұрын
They solve different problems
@williamdavid508
5 ай бұрын
When the configuration is many-to-many, what can the configuration be like in EF Core? Thank you very much for the video
@MilanJovanovicTech
5 ай бұрын
1. Navigations on both sides -or- 2. Join table (entity)
@williamdavid508
5 ай бұрын
@@MilanJovanovicTech According to DDD, is it convenient to use navigation from both sides? because in the aggregate we would have to directly associate the other aggregate and not the value object, it is somewhat confusing for me how many to many in DDD and I can hardly find any documentation🥲
@Engineer2261
5 ай бұрын
Great content, thanks!
@MilanJovanovicTech
5 ай бұрын
My pleasure!
@quangdt7181
10 ай бұрын
The value object cannot be replaced by the new record feature. One of reasons is value comparison. But, in any case, I enjoy your video.
@MilanJovanovicTech
10 ай бұрын
Value comparison is the exact reason to use records. What do you mean?
@nawarali1912
Жыл бұрын
I think we should use a separate set of classes that are responsible for data access and maybe use some libaray to map between the domain models calsses and the data access classes greate content thanks for your effort
@volodymyrliashenko1024
Жыл бұрын
I feel like this approach (to have a separate entity for the database) would be better in terms of flexibility and simplicity of EF Configuration.
@nawarali1912
Жыл бұрын
@@volodymyrliashenko1024 yes we can keep our domain models decoupled from the implementation details of the data access layer. This means that if we ever need to switch to a different data access framework, like Dapper, we can do so without affecting the rest of the application all the chages will be in the data access layer.
@MilanJovanovicTech
Жыл бұрын
In my opinion, it just adds a lot of overhead for not too much of a gain
@FranckMercado
Жыл бұрын
@nawarali1912 that's right because using EF Core, Dapper or any other mapper goes directly against DDD as it ties your domain model to infrastructure. Another approach would be to use your own interface for a mapper and then tie it up to an implementation of your liking. At the end it's a balance that each team would have to decide on.
@zgembofildzanic8796
Жыл бұрын
Let's say that the customer and order are persisted at the same time to the DB (through a single transaction). How would you then connect those related entities?
@MilanJovanovicTech
Жыл бұрын
If you think about it, that is unlikely to happen in a real-world scenario. But EF should be smart enough to first persist the customer, and then the order, so that referential integrity isnt broken
@zgembofildzanic8796
Жыл бұрын
@@MilanJovanovicTech I agree, customer and order are a horrible example, but I had cases where I have to save connected agregates within the same transaction.
@antonmartyniuk
Жыл бұрын
Great video, keep on making a useful stuff. Have you tried for a value objects a library ValueOf ? It's a good one with already written boilerplate code. In my projects, however I will use a slightly different approach. WebApi layer is always simple and doesn't know anything about your another layers of code. It doesn't know about DDD, strongly typed ids, etc. The same way I will do with database (persistent) layer. So repositories receive and return Dbo objects which are simple and stupid models. Then your services, CQRS handlers map Dbo to corresponding DDD objects. The service and CQRS layers is the most complicated layer in the application so it will benefit from DDD. Again it's how I am doing this
@MilanJovanovicTech
Жыл бұрын
ValueOf? Haven't heard of it 🤔
@suryasuresh1106
5 ай бұрын
Nice
@MilanJovanovicTech
5 ай бұрын
Thanks
@fritzjimenez9109
8 ай бұрын
Is it also good to use annotations? 🤔 specially for relations.
@MilanJovanovicTech
8 ай бұрын
I don't prefer it
@rohit704
Жыл бұрын
What if I want to store currency in a separate table in that case values object will work ?
@MilanJovanovicTech
Жыл бұрын
Like a list of currencies?
@rohit704
Жыл бұрын
@@MilanJovanovicTech Yes , want to fetch list of currency from databases.
@stunna4498
Жыл бұрын
what if u had an aggregate root called Player and another one called Team. A player can exist without a team so he would have a nullable field called TeamId? Team id. the Team aggregate root would have a private readonly List _playerIds= new (); How would you configure the entity type builder so that when u load a Team he will get the ids of the players inside the _playersIds field in team aggregate root?
@MilanJovanovicTech
Жыл бұрын
Use Include
@ilovepandaypoe6056
Жыл бұрын
is it possible to use database first with DDD?
@MilanJovanovicTech
Жыл бұрын
Of course
@banzeirao
4 ай бұрын
unfortunately not work when do a SELECT with a WHERE in entity framework 'could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly'
@MilanJovanovicTech
4 ай бұрын
What did you put in the WHERE statement...
@banzeirao
4 ай бұрын
@@MilanJovanovicTech after two days of research i discovered that need to be a implicit operator in value object and a primitive cast in LINQ query
@PelFox
Жыл бұрын
Theres a common recommendation to not use GUID as your PK (at least not as the clustered index). However, your domain entities should be persistence ignorant and need to be able to generate a unique ID. How do you usually deal with this?
@MilanJovanovicTech
Жыл бұрын
Take a look at EF HiLo, allows you to auto-generate the IDs without hitting the DB
@PelFox
Жыл бұрын
@@MilanJovanovicTech Just that MSSQL will by default make your PK clustered index if you do HasKey(), it's not good to use a GUID as the clustered index for your table.
@MilanJovanovicTech
Жыл бұрын
@@PelFox You can use an int/long as PK + HiLo strategy for EF to generate them without hitting the DB
@PelFox
Жыл бұрын
@@MilanJovanovicTech What I've done is keeping the GUID as a "Public ID" and having the int as PK but it's not really used from the consumers. But when using the same model for DDD and Data you will need to have both of these id's, which is persistance logic leaking into the domain model.
@swift8995
Ай бұрын
Why choose HasMany() over OwnsMany()? (Order, LineItems)
@MilanJovanovicTech
Ай бұрын
Entity vs Value object I consider a Line Item to have an identity
@carteja
7 ай бұрын
What if email was a value object and you wanted to use Complex types with an index. How can you map HasIndex on a complex type?
@MilanJovanovicTech
7 ай бұрын
From my testing, doesn't seem to be possible to create an index on a complex type through fluent API. That may change in some EF update.
@microtech2448
11 ай бұрын
Should Domain and Persistence not be ignorant to each other, so that they can be updated independent of each other and there should be mapper in some 3rd layer which keeps them mapped?
@MilanJovanovicTech
11 ай бұрын
You can do that, sure
@mouradaissani8957
Жыл бұрын
awesome, no need anymore for Entities Types (Infrastructure), and DDD types Entities Converters (automappers...)
@MilanJovanovicTech
Жыл бұрын
I do think that's overkill
@erlimar
Жыл бұрын
Top!
@MilanJovanovicTech
Жыл бұрын
Thanks!
@tmstechschool7239
11 ай бұрын
thank you, fyi OwnsOne was even part of EF Core 5 I think
@MilanJovanovicTech
11 ай бұрын
Probably even earlier?
@zbaktube
Жыл бұрын
Some logic goes to config, and not in the domain model itself. So, if we can add the constrains as attributes + change make an auto configuration according to that...
@MilanJovanovicTech
Жыл бұрын
I don't like using attributes
@zbaktube
Жыл бұрын
@@MilanJovanovicTech Hehe, and I totally understand why 🙂 But lets assume we do, and we can mark for example the email field unique. But that check only can happen in your infrastructure, not in your domain. So your domain kind of lack that info. Ok, we can make it Id, but then it has security concerns. We can encode it to hide the content, but then we save the same info twice now. Then, lets put all logic to a third place, and we are now at an anemic model...
@georgebelletty7861
Жыл бұрын
great video
@MilanJovanovicTech
Жыл бұрын
Glad you enjoyed it
@mijaelcallejas4406
11 ай бұрын
but what happened to the database? :(
@MilanJovanovicTech
11 ай бұрын
Nothing
@enciphered7650
Жыл бұрын
I still see no point of using a rich domain model. WHY! JUST WHY! All this code and it could just be written in command handlers.
@MilanJovanovicTech
Жыл бұрын
Study about domain-centric architectures
@enciphered7650
Жыл бұрын
@@MilanJovanovicTech why can't the domain be a collection of request and handers ? I feel like coding the domain in the way you show locks you down while handlers can have pipelines but this can't. So I'm just having a hard time wrapping my head around why anyone would prefer this over that.
Пікірлер: 205