Callum
Callum
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
Well DTOs are best practice so that'd make logical sense to me.
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
I think you can also use .Select?
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
This has been written in notepad just now so if there's any mistakes..
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
which I think should serialize fine?
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
public class PeopleDTO
{
public string Name { get; set; }
public IEnumerable<string> GroupNames { get; set; }
}

var peopleWithGroups = await _dbContext.People.Select(p = > new PeopleDTO
{
Name = p.Name,
GroupNames = p.Group.Select(l => l.GroupName).ToArray()
});

return peopleWithGroups;
public class PeopleDTO
{
public string Name { get; set; }
public IEnumerable<string> GroupNames { get; set; }
}

var peopleWithGroups = await _dbContext.People.Select(p = > new PeopleDTO
{
Name = p.Name,
GroupNames = p.Group.Select(l => l.GroupName).ToArray()
});

return peopleWithGroups;
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
so you could do something like...
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
I suggest we return a PeopleDTO that has the properties of I dunno group names
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
Anyways if we do want to use a DTO...
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
so I'm reluctant to say one or the other tbh
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
I've worked with people whom have venemously sworn by either or and I've seen both play out successfully or badly tbh. But I suppose the same could be said for any "good practice" if you abuse it bad enough
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
apologies...
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
I just don't see it as a black or white answer...
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
We haven't even asked the OP if they want to use a DTO or not?
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
I feel I've rambled off on one when we just have a simple many to many endpoint
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
Anyways sorry to detract from the conversation
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
If they hard code ids and it breaks then that's on them for their shoddy integration
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
But I accept serialization business logic isn't pretty and hence I try to avoid "sensitive" information on endpoints that I expose. Ids to me are fine as consumers can delete stuff as well or retrieve stuff by id
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
if I did it using DTOs I'd have to tell OData the mapping between the two and do some complicated business logic mapping code such that the IQueryable for the DTO could be translated to an IQueryable for the domain model
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
Again though I use OData so that people can get custom cuts of their own data without me building many endpoints
86 replies
CC#
Created by big OOF on 2/16/2023 in #help
✅ API result
and now anytime OData encounters that property it won't serialize neither show metadata for their property
86 replies