2
Hello,
I have a question regarding the Efcore Webapi of ASP.NET Core.
I have my Service, Professional, User and Scheduling entities, where in the service I have a foreign key for the professional and in scheduling for professional and user.
When I make a request for the endpoint /services, I receive the following JSON:
[
{
"descricao": "Servico Primário",
"valor": 109.99,
"profissional": {
"servicos": [],
"nome": "Profissional",
"cpf": "00000000001",
"endereco": "Rua A",
"idade": 22,
"email": "[email protected]",
"senha": "123456789",
"id": 1
},
"agendamentos": [
{
"data": "2019-08-22T19:30:40.573",
"finalizado": false,
"usuario": null,
"id": 1
}
],
"id": 1
}
]
The above structure is generated by following this code:
using System.Collections.Generic;
using System.Linq;
using Fusion.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace Fusion.Infra.Data.Repositories
{
public class ServicoRepository : BaseRepository<Servico>
{
public override IList<Servico> SelectAll()
{
return context.Servicos
.Include("Profissional")
.Include("Agendamentos")
.ToList();
}
public override Servico Select(int id)
{
return SelectAll().FirstOrDefault(x => x.ID == id);
}
}
}
My question is as follows, how do I hide in this request in specific fields professional.password, professional.servicos and schedules.usuario?
unfortunately using Rest the only way would be to do another dto without the attribute in question and map it, to be able to bring results more dynamically, I believe you need to try something like graphql
– Lucas Miranda
That’s exactly what I did and what worked for Lucas. Thank you so much for your help!
– Kelvi Dalmazo