BL Mapping help

I have finished my BL DTO's and want to map my DTO with the EF DAL How do I map it when inside the create DTO is a another CreateDTO?
// Table Actions of the table
public List<RestauraceAkceStoluCreateDto> AkceStolu { get; set; } = [];

// All the products in the Table
public List<RestauraceObjednavkaPolozkyCreateDto> Polozky { get; set; } = [];
// Table Actions of the table
public List<RestauraceAkceStoluCreateDto> AkceStolu { get; set; } = [];

// All the products in the Table
public List<RestauraceObjednavkaPolozkyCreateDto> Polozky { get; set; } = [];
https://pastebin.com/8hmUZ2Ay
Pastebin
Code - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
13 Replies
taner.
taner.2w ago
Do u use Mapster or AutoMapper?
Mayor McCheese
Automapper is generally not recommended. It's very easy for things to go wrong I usually just map by hand unless I've got some cross cutting mapping concern I want enforced
taner.
taner.2w ago
That’s why I’m asking
Mayor McCheese
Some people just do a ToDTO, FromDTO in the DAL object. Others use mapping classes. Being consistent is more important here imho
taner.
taner.2w ago
Make an extension method for this class and then u are good to go
Mayor McCheese
That's another option for certain Consistency is key
spit on that Thang CHO BOC
Mapperly
taner.
taner.2w ago
Im pretty sure u can define specific mapping options for the object
spit on that Thang CHO BOC
The thing is i don't have much experience with mapping and DTO's Should I ignore it or Map it? The child DTO is the question since I have everything required since I had imagined it worked that way I have to define(map) the whole create dto if that scenario happends or can I just opt to ignore it
taner.
taner.2w ago
from what i see it should be handle. Here is a pic. from maperly how u create a mapper:
No description
spit on that Thang CHO BOC
Ohh okay I thought directly using [MapProperty]
Mayor McCheese
I want front end DTOs to be as flat as possible
spit on that Thang CHO BOC
Should I just put raw EF entities instead of CreateDto's?
// Order header record
public class RestauraceObjednavkaHeaderCreateDto
{
public string? HeaderId { get; set; }
public required int StulId { get; set; }
public Status StatusStolu { get; set; } = Status.Open;

// Table Actions of the table
public List<RestauraceAkceStoluCreateDto> AkceStolu { get; set; } = [];

// All the products in the Table
public List<RestauraceObjednavkaPolozkyCreateDto> Polozky { get; set; } = [];
}
// Order header record
public class RestauraceObjednavkaHeaderCreateDto
{
public string? HeaderId { get; set; }
public required int StulId { get; set; }
public Status StatusStolu { get; set; } = Status.Open;

// Table Actions of the table
public List<RestauraceAkceStoluCreateDto> AkceStolu { get; set; } = [];

// All the products in the Table
public List<RestauraceObjednavkaPolozkyCreateDto> Polozky { get; set; } = [];
}
The logic I wanted to concieve: The waiter (role we getting from auth) opens up a table it will create using this DTO He can Directly order items(polozky) on the specified table Id . And the Action will be created immediately because I track Opening tables too. The Entity I am refering to:
public class RestauraceObjednavkaHeader
{
public required string RestauraceObjednavkaHeaderId { get; set; }

// Foreign key | Restaurace_Akce_Stolu N:1 Header
public required ICollection<RestauraceAkceStolu> RestauraceAkceStolu { get; set; } = [];

// Navigation property | Restaurace_Objednavka_Header N:1 Stul
public required int StulId { get; set; }
public required Stul Stul { get; set; }

// Table status
public required Status StatusStolu { get; set; } = Status.Open;

// Navigation property | Restaurace_Transakce_Id N:1 Header
public required ICollection<RestauraceTransakce> Transakce { get; set; } = [];

// Navigation property | Restaurace_Objednavka_Header 1:N Polozka
public required ICollection<RestauraceObjednavkaPolozky> Polozka { get; set; } = [];
}
public class RestauraceObjednavkaHeader
{
public required string RestauraceObjednavkaHeaderId { get; set; }

// Foreign key | Restaurace_Akce_Stolu N:1 Header
public required ICollection<RestauraceAkceStolu> RestauraceAkceStolu { get; set; } = [];

// Navigation property | Restaurace_Objednavka_Header N:1 Stul
public required int StulId { get; set; }
public required Stul Stul { get; set; }

// Table status
public required Status StatusStolu { get; set; } = Status.Open;

// Navigation property | Restaurace_Transakce_Id N:1 Header
public required ICollection<RestauraceTransakce> Transakce { get; set; } = [];

// Navigation property | Restaurace_Objednavka_Header 1:N Polozka
public required ICollection<RestauraceObjednavkaPolozky> Polozka { get; set; } = [];
}
But when I use the CreateDto's I need to specify their Entity too (making sense that I would need it to specify) But that seems to me like Service rather than Mapping as a whole

Did you find this page helpful?