No video

.NET 6 🚀 AutoMapper & Data Transfer Objects (DTOs)

  Рет қаралды 71,452

Patrick God

Patrick God

Күн бұрын

Пікірлер: 114
@PatrickGod
@PatrickGod Жыл бұрын
🚀 Join the .NET Web Academy with a 30% discount - closing soon! 👉 www.dotnetwebacademy.com/courses/academy?coupon=dnwas23yt
@stephenohaeri2472
@stephenohaeri2472 Жыл бұрын
there iis something so special about your videos, i am a .Net developer and i will cherish your videos anytime anyday
@andreiene8695
@andreiene8695 Жыл бұрын
13:32 in that case you can simply add .Reverse() and you won't need to write another line
@ericfleet9602
@ericfleet9602 Жыл бұрын
Correct, except it is .ReverseMap()
@PatrickGod
@PatrickGod Жыл бұрын
Thank you! You live and learn! :)
@PatrickGod
@PatrickGod 2 жыл бұрын
Btw, we can also use this line to map the heroes collection: *return _mapper.Map(heroes);* 🤩
@ferenc3460
@ferenc3460 2 жыл бұрын
I will try to use it ín my HairSalon project 🙂 would you make a video about tricky stuff like sending list of objects to the controller properly and for instance with dynamic objects from the client side? Such as adding multiple skills or items to the superhero. Actually, I can do this stuff but I would watch some concepts from you 🙂
@jayanandajena8268
@jayanandajena8268 2 жыл бұрын
Hi Patrick God, I have watched all of your videos and learned so many thing, so I have a request to you that can you please make a video on 2 factor authentication like we can send OTP to multiple phone number with different OTP and we validate that both at a time. Its a request thank u so much.
@SantiagoDSCA
@SantiagoDSCA Жыл бұрын
you can try with CreateMap().ReverseMap() it allows the mapping in both directions, so you dont need to add the other line :D
@PatrickGod
@PatrickGod Жыл бұрын
@@SantiagoDSCA Thank you! You live and learn! :)
@kopilkaiser8991
@kopilkaiser8991 8 ай бұрын
This is the first time I've learnt about AutoMapper and it seems so powerful and useful! This will make it so much easier to convert one class data to another. You are a lifesaver and a gold resource of knowledge. Cheers🎉🎉🎉
@10Totti
@10Totti 2 жыл бұрын
i also use mapper in this mode: CreateMap().ReverseMap();
@dasfahrer8187
@dasfahrer8187 2 жыл бұрын
Beat me to it. :)
@devtekve1396
@devtekve1396 2 жыл бұрын
Tho this only works if you are not doing any explicit mapping for members
@devtekve1396
@devtekve1396 2 жыл бұрын
I believe you should also know that auto mapper is easy to be abused and start doing things you probably shouldn’t. That being said, I’m a huge fan of it and use it a lot at production environments!. One big caveat is that auto mapper doesn’t support asynchronous operations, so if you want to do resolve some things asynchronously it won’t help you there. There are things you could do to make that work but beware it’s not intended for that. Another thing also worth mentioning is that auto mapper is slow, I believe it uses reflection, but hasn’t been a problem for me anyways. One more thing, your object will require a parameterless constructor to support automapper. Would be interesting to see a video about alternative approaches to Automapper that make your life as easy as it does
@micha8469
@micha8469 2 жыл бұрын
I sorta agree. I used to use it almost in every project, that wasn't really my, but rather team/head's decision, and I am glad I don't use it anymore. There is literally nothing in it rather than more code that you have to (should) cover with tests and things that can go wrong underneath. - If Entity->Poco mapping is easy then manual mapping is also easy: entity.Select( x => new Dto() { fill props} ); - If Entity->Poco mapping is complex, the manual mapping is more difficult, but is safer and you have full control over it. With Automapper, you need good tests to make it safe. Either way a manual mapping has a slight advantage in my opinion, not to mention performance factor. There are many articles about Automapper issues and flaws, no need to list them here, everyone interested can google it easily. Do you know any people who resigned from it and came back to it again? I honestly don't unless it was forced to us in a project.
@SebVEVO
@SebVEVO Жыл бұрын
@@micha8469 I disagree that it has nothing in it because it happened so many times that when a feature or even a minor change is made, people often forget to update the Mappings that leads to direct or unseen bugs. Maintenance in medium-sized projects can even be taxing. AutoMapper solves those issues by removing all those Mappings methods. However, AutoMapper should not be used because of Performance and Diagnostic issues especially in production.
@MahmoudMouradSidky
@MahmoudMouradSidky 2 жыл бұрын
30 degree is freaking hot!!! You should come to Egypt and try the 42 degree
@muttBunch
@muttBunch Жыл бұрын
Amazing tutorial, thank you. Oh and nice shirt!!! I love how it looks sandy for a beach shirt.
@PatrickGod
@PatrickGod Жыл бұрын
Thank you very much! Fun fact: I actually got the shirt in Hawaii. You know, close to the beach. 😅
@nguyenhuuanhtuan5360
@nguyenhuuanhtuan5360 Жыл бұрын
Thanks for the detailed explaination, I did some google search about automapper for my project but your video made it so clear for me ❤❤
@divanvanzyl7545
@divanvanzyl7545 Жыл бұрын
Hey Patrick, love your videos. As a South African, I always laugh at Europeans who call early 30 degrees hot😂 try 40+ celcius, then you can talk😂 I had the privilage of visiting your amazing country this year and I highly reccomend it to any traveler. Thank you for all your great content. Ive learned a lot from you, as have so many others.
@PatrickGod
@PatrickGod Жыл бұрын
Awesome! Thank you so much. Where in Germany have you been?
@fshyjp
@fshyjp 2 жыл бұрын
Thank you, Patrick! This is right the information that I wanted.
@franciscogilt
@franciscogilt 2 жыл бұрын
Patrick God -> 0, VS2022 - 5, The Battle xD, Overall awesome introduction to Automapper.
@PatrickGod
@PatrickGod 2 жыл бұрын
Indeed, it's a battle sometimes. 😅
@minashokrallameichael5998
@minashokrallameichael5998 2 жыл бұрын
Great topic I am a big fan of you, small note I want to add you dont need to convert to Dto one by one using linq, Automapper support collection
@PatrickGod
@PatrickGod 2 жыл бұрын
Awesome! Thank you very much. You live and learn. 😊
@minashokrallameichael5998
@minashokrallameichael5998 2 жыл бұрын
@@PatrickGod sure and really I like your way of explaining, congratulations really
@theodorn
@theodorn 2 жыл бұрын
Thanks a lot! Take a vacation in Sweden, it's cooler. 😀
@skg7958
@skg7958 2 жыл бұрын
Thanks! Patrick. As always, love your topics and presentation
@aagastyapathak
@aagastyapathak 2 жыл бұрын
Thanks, Patrick Always learning great thing from you
@khalidracabov5347
@khalidracabov5347 2 жыл бұрын
Love you so much dude. Keep up the good work
@PatrickGod
@PatrickGod 2 жыл бұрын
Thank you! ❤
@imadabab
@imadabab 3 ай бұрын
Brilliant video. Thanks a lot.
@properwaffles
@properwaffles 10 ай бұрын
Thanks!
@PatrickGod
@PatrickGod 9 ай бұрын
Thank you!!
@mindsetiseverything6362
@mindsetiseverything6362 3 ай бұрын
Thank you.❤
@PatrickGod
@PatrickGod 3 ай бұрын
You are so welcome
@raggardy
@raggardy 2 жыл бұрын
Hi Patrick. Great video. I was wondering if you've ever used Mapster? What are your thoughts if you have and maybe that could be a video for the future?
@davidheale6435
@davidheale6435 2 жыл бұрын
Mapster for the win.😄
@PatrickGod
@PatrickGod Жыл бұрын
It's great! Even easier to use than AutoMapper. We will use it in the .NET Web Academy. 😊
@farhanpirzada4228
@farhanpirzada4228 Жыл бұрын
how to install this package in class library project ??
@stevemcqueen2887
@stevemcqueen2887 11 ай бұрын
hahaha "Visual Studio, Jesus Christ... what is going on here?" well said 🤣🤣🤣
@dantecavallin8229
@dantecavallin8229 Жыл бұрын
What about if the two types are in different assemblies? Isn't that a more realistic usecase?
@AliFrazK
@AliFrazK 2 жыл бұрын
Nice.
@PatrickGod
@PatrickGod 2 жыл бұрын
Thanks!
@markgamal7250
@markgamal7250 25 күн бұрын
where i live it is 40 C degrees in summer in a usual day
@Lukindify
@Lukindify 2 жыл бұрын
If you use mongodb, you don't need to use an automapper to return. The mongodb driver already have a translator, the extension "As", and you can use the extension "Lookup" to manipulate fields.
@chesster5981
@chesster5981 Жыл бұрын
Yeah but js is gross af 🤮
@zulhishamtan4308
@zulhishamtan4308 Жыл бұрын
Hi Patrick, thanks for the video. My question may sound stupid... Anyway, I would like to know when was the AutoMapperProfile class being call? When was the createMap statement being executed? Appreciate if you could make my mind clear. Last but not least, could please make a video for authentication webAPI.? Thank you very much.
@svenkicherer
@svenkicherer 2 жыл бұрын
9:17 could you explain why you are using the linq statement? what is the benefit? you could just return _mapper.Map(heroes)
@PatrickGod
@PatrickGod 2 жыл бұрын
Because I didn't know that. 😅 Thanks a lot for sharing! Works like a charm. 😊
@svenkicherer
@svenkicherer 2 жыл бұрын
@@PatrickGod sometimes automapper is really nice 😉
@oveskhan687
@oveskhan687 10 ай бұрын
Hi Patrick, we would like to see tutorial video on .Net 6 Azure :)
@sahildhingraa
@sahildhingraa Жыл бұрын
!completed
@HenkvanderGeld
@HenkvanderGeld Жыл бұрын
Hi Patrick, can there be a reason to use separate DTO's for [1] transferring data from client to server and [2] transferring data from server to client. For all of our models (250+) we have 2 DTO's; so for e.g. model Employee we have EmployeeReadDto and EmployeeEditDto. This also means that we have a lot of mapping configurations; Employee -> EmployeeReadDto, Employee -> EmployeeEditDto and EmployeeReadDto -> EmployeeEditDto. Most of the time the difference between the 2 DTO's is only the Id property (xxxReadDto has an Id and the xxxEditDto has not). Having the distinction brings a lot of extra code and configuration. Is it really necessary to have this distinction or can everything be done with 1 dto, e.g. EmployeeDto?
@marciliojrr
@marciliojrr Жыл бұрын
I need this too
@torrvic1156
@torrvic1156 6 ай бұрын
Very good question. I think that it should be separate but I am not experienced so I would like to know this too.
@meoconhoccode
@meoconhoccode Жыл бұрын
ty
@Duelweb
@Duelweb 2 жыл бұрын
Brilliant!
@James66662
@James66662 Жыл бұрын
Thanks dude , works perfect
@raphaeldevmtb
@raphaeldevmtb 2 жыл бұрын
Great! Thanks
@PatrickGod
@PatrickGod 2 жыл бұрын
You're welcome!
@eradubbo
@eradubbo Жыл бұрын
Automapper = instant technical dept
@WoodyandAsh
@WoodyandAsh Жыл бұрын
Hi Patrick. Can you explain how it just works after creating the AutoMapperProfile class? Perhaps I missed it but I didn’t see you initialise or inherit that code anywhere. What am I missing?
@todo667
@todo667 Жыл бұрын
7:29 He's using dependency injection and adding an IMapper interface in the SuperHeroController constructor
@waynehawkins654
@waynehawkins654 Жыл бұрын
Thanks for the video. This is like many I have seen, and all use API with EF. What I like to see is full EF without API, using Class calls to Add,Update,Deleted DTO changes in EF. I have all working, but when I try and do a Update by passing a DTO back in to EF to do a update, I get errors. I will keep looking, but I hope to find a full video solution that show how to use EF with DTO and AutoMapper without using APIs.
@junior.santana
@junior.santana Жыл бұрын
Have you found what you were looking for? From my understanding, your issue is not related to API, you shouldn't pass the DTO to EF since it's just a "Data Transfer Object", you should map to the corresponding entity and then pass that to EF/DbContext
@starswarslandoseries
@starswarslandoseries Жыл бұрын
Thanks Patrick, You are a God
@Simao-xk1ye
@Simao-xk1ye 2 жыл бұрын
Thank Patrick for this topic, what if we dont want to map some properties of dto ?
@shuvbhowmickbestin
@shuvbhowmickbestin Жыл бұрын
30 degress *freaking hot* 🙂🙂. Europeans don't really use air conditioners, do they? Also really nice video. I previously did a Udemy course which explained everything perfectly but didn't mention *WHY* Mapping profiles were used. So you showed us that here, it's basically like a policy/rule that allows the mapping right? but the real mapping happens with the *_mapper.Map()* method. Thanks a lot for the video.
@choripower
@choripower Жыл бұрын
In profile u can add .ReverseMap(); so u dont copy code
@TommiLipponen
@TommiLipponen Жыл бұрын
How to handle related data with automapper and DTO:s? Like if there is a table for super powers that every hero may have one or many. How to get a list of super heros including their super powers when using automapper and DTO:s?
@ericfleet9602
@ericfleet9602 Жыл бұрын
13:40 - Instead of two lines, just use .ReverseMap()
@harchizia
@harchizia Жыл бұрын
Is that really work?
@jadissonamorim6010
@jadissonamorim6010 2 жыл бұрын
Patrick, could you record a video about DDD (Domain Driven Design)?
@PatrickGod
@PatrickGod 2 жыл бұрын
Noted!
@abdulmussawir3132
@abdulmussawir3132 Жыл бұрын
Hello Patric Hope you doing well, As per your thinking Auto Mapper Map Performance it's slow or not ?
@amichelis
@amichelis 2 жыл бұрын
Why not writting a simple explicit typecasting opperator from SuperHero to SuperHeroDto and just do "return Ok(heroes.Select(x => x as SuperHeroDto));" ?
@amichelis
@amichelis 2 жыл бұрын
Could also work with heroes.Cast(). Also, you ommited the ID from your DTO. How did that worked when mapping from DTO to Entity?
@stephenhauck
@stephenhauck 2 жыл бұрын
I really like your content so thanks but why would I use this when it can obfuscate the names of properties when transposing them between objects when I can just use Newtonsoft or MS code generators and convert them using JSON property mapping ?
@jesspants383
@jesspants383 11 ай бұрын
Is it case sensitive. Will it have a problem mapping from Id to id?
@marciliojrr
@marciliojrr Жыл бұрын
Hello @PatrickGod, First of all, I wanted to say that your video was excellent, just like all the others. I was wondering if you could explain to us how to use AutoMapper for entity editing. In the system I'm developing, we use a DTO to add a new entity (for example, SuperHeroDto), and in the Service layer, it is transformed into a "regular" entity (SuperHero). This works well. However, I have some doubts when it comes to editing an existing record. The issue arises because, during the post request, it uses the mapping configuration from when the object was created. As a result, some things that should be preserved are changed (e.g., Id, Creation Date). It might be something simple, and I might be overcomplicating things, but if you could help me understand how AutoMapper works for both adding and editing entities, it would be immensely helpful in advancing my projects at the company where I work. Currently, the mapping between DTO and the "regular" class is done manually. Thank you very much and best regards.
@stevejackson2643
@stevejackson2643 Жыл бұрын
Visual Studio clearly doesnt like the heat either
@meirkr
@meirkr Жыл бұрын
Is there a place to map also mapping between models and DB entities, in order to hide DB related stuff (special properties for Mongo or EF core)?
@denis-gd1xc
@denis-gd1xc Жыл бұрын
Hey Pattrick, im writing a project and i have a class library that has all the repositories and i want to map from the repository itself and then return the value, how i can do it?
@ACertainWebDeveloper
@ACertainWebDeveloper Жыл бұрын
Can I create an universal AutoMapperProfile? Like if I got 50 models, do I have to create 50 AutoMapperProfiles?
@denis-gd1xc
@denis-gd1xc 2 жыл бұрын
Great video, if I have multiple entries other then the superhero, I will need to create multiple profiles or I can create it all in the same profile?
@PatrickGod
@PatrickGod 2 жыл бұрын
Thank you! Should work in the same Profile. Just add the other mappings there. Cheers!
@denis-gd1xc
@denis-gd1xc Жыл бұрын
Hey Pattrick, the automappers faills only when i try to get the object by id its same error as in the vid its strange becase the getall method work and its same mapping do you know why this pronlem occurs?
@Beji-boy
@Beji-boy 2 жыл бұрын
I wanna ask if you using Automapper so how you use Entity Framework ? Which differents is between Automapper vs Entity Framework. And if I wanna use Automapper and Entity Framework in one project. So Which one is good use it? Thanks for answer
@devtekve1396
@devtekve1396 2 жыл бұрын
Entity framework and automapper serve two different purposes. Automapper is just a convention based object mapper, while entity framework is meant to manipulate the objects and persist them on a backend while treating them as simple objects (not worrying about database code [too much anyways …] ) You can use automapper and entity framework together. If you do the mapping the way he did it on the video, you’ll be creating a new object with the properties mapped from the other. However, you can map the properties of one object INTO Another object, which is essentially like manually assigning the properties to the existing object, which is what entity framework wants. You do this by doing something like _mapper.map( source, destinationObject);
@softwareenthusiasm3667
@softwareenthusiasm3667 2 жыл бұрын
Tried to AutoMapper.Extensions.Microsoft.Dependen and got error Severity Code Description Project File Line Suppression State Error Package restore failed. Rolling back package changes for 'AutoMapper'.
@sphazwelakhe2784
@sphazwelakhe2784 Жыл бұрын
Hi Patrick, can you please demo a [HttpGet] method for updating existing model with Automapper.
@farhanpirzada4228
@farhanpirzada4228 Жыл бұрын
when i trying to install its throwing error cycle detected
@devalefsilva
@devalefsilva 2 жыл бұрын
.ReverseMap()
@mhdip6453
@mhdip6453 Жыл бұрын
i m just watching everyone automapper tutorial everyone just showing how to use automaper to fetch data only one table i don't find any solution.. when it comes to the join table .. How to use join with automapper.. can you make video about this.
@king_naashik9266
@king_naashik9266 2 жыл бұрын
Hello sir can u do a .net crud programme with clean Architecture
@philipm1896
@philipm1896 2 жыл бұрын
Sometimes I wonder if all these overhead bulky tools for making SQL queries are even worth it when the raw SQL queries are x10 faster and configurable on the fly.
@SupahSamie
@SupahSamie 2 жыл бұрын
Not as safe though, wouldn’t you say?
@philipm1896
@philipm1896 2 жыл бұрын
@@SupahSamie Very safe if you use add with parameters if parameters are passed in.
@SupahSamie
@SupahSamie 2 жыл бұрын
@@philipm1896 Yeah, not just injection safe is what I’m saying. The ORM makes writing queries safer I thought but I could be wrong
@yashwanthd1998
@yashwanthd1998 2 жыл бұрын
More readable and maintainable and it is not slow . Using raw queries is pain use to do in php
@mohammedalbosifi3975
@mohammedalbosifi3975 2 жыл бұрын
We want toturial about identity server 4 and than you
@Synergy_World
@Synergy_World 2 жыл бұрын
33 is nothing in South Africa 🇿🇦🇿🇦we currently on 120degreess
@bramburn
@bramburn 2 жыл бұрын
You have any T-shirt I can buy
@GoryWory
@GoryWory Жыл бұрын
superheroes? how old are you, 5?
@krillcasey
@krillcasey 2 жыл бұрын
It seems like a lot of work ....
@Erril-1
@Erril-1 3 ай бұрын
Please stop using Automapper, it looks good at the beginning but it cost us so much more time and nerves in the long run. It's totally not worth it! If I wanted to not have references in my mapping code, I would have used plain JavaScript. 👎
@mahfujurrahman1016
@mahfujurrahman1016 Жыл бұрын
spider man's place should me Brooklyn
@bananasba
@bananasba 2 жыл бұрын
You'd better think twice before start using automapper for anything serious. Authors of this library will always say that it is your fault, your problem and you are using it wrong and you will be left alone with this tool and your problems. They also like to do breaking changes without any option for fallback. No library should dictate you what to do in your own code.
@dputra
@dputra 2 жыл бұрын
Wow really? That surprised me. I was gonna use it for my future projects but seems like we'll stay away for anything serious.
.NET 6 - AutoMapper & Data Transfer Objects (DTOs) 🗺
54:41
Mohamad Lawand
Рет қаралды 16 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 158 М.
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 46 МЛН
Мы сделали гигантские сухарики!  #большаяеда
00:44
Don't Use AutoMapper in C#! Do THIS Instead!
16:17
Codewrinkles
Рет қаралды 68 М.
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 42 М.
The Best .NET Mapper to Use in 2023
11:57
Nick Chapsas
Рет қаралды 93 М.
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 273 М.
Why do we use DTOs in our APIs?
26:15
Codewrinkles
Рет қаралды 9 М.
Why to use DTO (Data Transfer Objects)
11:02
Study Mash
Рет қаралды 32 М.
Send Email with a .NET 6 Web API using Mailkit & SMTP 📧
22:02
Patrick God
Рет қаралды 72 М.
ASP.NET Core Web API .NET 8 2024 - 5. DTOs
8:27
Teddy Smith
Рет қаралды 26 М.