Basics (How does an enterprise do it?) DAL Entity mapper
Currently I am doing a web app since my last small project in the same field (web app in C#)
I wanted to ask a difference between (In DAL or even BL)
I will be doing my entities like this
If something like... maybe abstract class or something else would work well.
I have another question in my last project i was using AutoMapper for my BL mapping. What I heard was Mapperly being faster if you can give some insight.
and also to challenge myself for future proofing what would be the most common enterprise environment solution would have been? (if they even chose C# at all)
14 Replies
this would be my structure to my DAL
this looks strange to me. wouldn't you check if the corresponding entry exists (e.g.
...FirstOrDefault(x => x.ID == ...
) by which you would fetch the existing entry and then just use a mapping method of this entity instead of creating own mapper classes interfaces and more bloat?Hmm? I thought when creating the database code first i had to somehow map the entity that code in the entities folder
What I do is in the Dal at least is to tell existing object = new.object
you have your dbcontext where you can access the existing entries via linq
when you add a new entry, you just instanciate it (as usual), add it to your dbcontexts dbset<T> and then save the changes
Yeah I see the problem now...
So whole time I was doing nothing
It hit me when in my old web app there are no references
when you apply the users input to create/update an entity, you usually do this directly. ofc, you could add a particular ctor or mapping method within the entity class if it makes things easier for you. but you do not need additional mapper classes.
last but not least there are DTOs which you could/would need to map. but also: you could implement the mappings directly in the corresponding entity or DTO classes.
Yea I have those in my BL
Would you mind to check if some things / better methods are better (it was a uni project of 3 people still got A but janky as hell)
In conclusion DAL should only hold entities repository (the things it can interact) and some Basic generation to the empty database?
you need the migrations and api endpoints
migrations are done automatically didnt try yet but i think it works EF icon shows up in every entity i made
automatically? you need to execute
dotnet ef migrations add <name>
i meant that sorry
perhaps they are then auto applied to your db when you have implemented the logic
e.g. via
from the student in my project i see
if you could see what https://github.com/ThangChoBoc/DALandBL
GitHub
GitHub - ThangChoBoc/DALandBL
Contribute to ThangChoBoc/DALandBL development by creating an account on GitHub.