C
C#2y ago
Dreams

How to structure this DTO?

Should I flatten this? I'm not sure how to make nested objects with C#. My old-ish DTO model (before needing localization) looks like this:
c#
public class DynamicContentDTO
{
[Required(ErrorMessage = "Id is required.")]
public string Id { get; set; } = null!;

[Required(ErrorMessage = "Type is required.")]
public string Type { get; set; } = null!;

[Required(ErrorMessage = "Value is required.")]
public string Value { get; set; } = null!;
}
c#
public class DynamicContentDTO
{
[Required(ErrorMessage = "Id is required.")]
public string Id { get; set; } = null!;

[Required(ErrorMessage = "Type is required.")]
public string Type { get; set; } = null!;

[Required(ErrorMessage = "Value is required.")]
public string Value { get; set; } = null!;
}
7 Replies
Dreams
DreamsOP2y ago
i'm just going to flatten it
ero
ero2y ago
That's crazy, why even make a post at all if you're gonna make up your own mind not even 5 minutes later oh, that's from yesterday
Angius
Angius2y ago
Rubberducking lol
ero
ero2y ago
Wait no I'm just fucking stupid, it just turned 12am for me lmfao
Anton
Anton2y ago
you just make another class with those properties and just have that class as a property. model binding handles nested objects no problem
Dreams
DreamsOP2y ago
@AntonC thank you
Anton
Anton2y ago
np
Want results from more Discord servers?
Add your server