4
I’m performing a consultation using Select
, to select only the required fields and consequently have higher performance.
In my View
user can choose certain fields to be loaded
Man ViewModel
public class CliViewModel {
public bool CarregarNome {get;set;}
}
and in my select
var entity = context.Clientes.AsNoTracking()
.Select(cli => new {
if(viewModel.CarregarNome) {
x.Nome
}
}).ToList();
Of course this expression of error, but is there any way to do something similar ?
It depends on your return could have conditional so var return = Entity. Select(x => new { Name = viewModel.Loadable == true ? x.Name : String.Empty });
– Marco Souza
That’s actually a chuncho, and
Nome
is defined as such, without any performance gain.– Leonel Sanches da Silva