0
Just for learning even, understand the section. I did a lambda of a bank with only 6 fields, like this:
public List<LiberacaoDTO> getAutoriza(int idorcamento)
{
var lista = contexto.Liberacoes
.Where(m => m.IdOrcamento == idorcamento)
.Select(m => new LiberacaoDTO
{
TipoVenda = m.TipoVenda,
Juros = m.Juros != 0 ? m.Juros : 0,
Entrada = m.Entrada != 0 ? m.Entrada : 0,
MaxComi = m.MaxComi,
Cliente = m.Cliente,
Filial = m.Filial
})
.ToList();
return lista;
}
When the service returns, it brings all the fields. Only those listed in the expression, with value, the others have null or 0. But why all fields and not only those listed in the expression? Below the call of my service:
public class LiberacaoController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
PedidoLiberacao liberacao = new PedidoLiberacao();
[AcceptVerbs("Get")]
public IEnumerable<LiberacaoDTO> getLiberacao()
{
return liberacao.getAutoriza(1000012093).AsEnumerable().ToList();
}
}
I understood Thiago, I’ve done so and had difficulty in the return, but I think it is because I expected a Liberacaodto and so gave dick and left aside, because I solved as indicated in the post. I will try this approach by returning a
object
, and see if caught. Because this will be consumed in an Android App (Xamarin) and the less irrelevant data, the better, I think.– pnet
If you don’t need this data maybe it’s a better idea to clean up your DTO, or create another DTO that has only what it takes. The DTO does not need to be a reflection of the bank in all cases.
– Thiago Silva
A DTO can have fields of two or more tables, to be used only in an expression that requires these fields?
– pnet
Yes, but the best way to do it is to create two Dtos and one to have a property that is the other.
– Thiago Silva
Like getting a Icollection<Other> from another? That’s it?
– pnet
That’s right. See my answer in your other question.
– Thiago Silva