0
I have the query
below, but while trying to format the field Data_nascimento
and Data_exclusao
with the .ToString("dd/MM/yyyy")
returns me to an error at runtime.
The 'System.String Tostring(System.String)' method has no conversions SQL supported.
var dependentes = (from dependentes in ctx.Tabela_DocsItens
where itens.Controle == dependentes.Controle_titular
select new listaDependentes
{
carteirinhaSegurado = dependentes.Cod_identific,
nomeSegurado = dependentes.Segurado,
dataNascimento = dependentes.Data_nascimento.Value.ToString("dd/MM/yyyy"),
dataExclusao = dependentes.Data_exclusao.Value.ToString("dd/MM/yyyy"),
}).ToList();
Is there any way to convert this before materializing the object, ie throw to the database a query
that returns the data fields in the format I want?
It has some difference if I use Tolist() instead of .. Asenumerable() ?
– Marco Souza
@Marconciliosouza the idea of the
AsEnumerable
at this point is only to force the query with theBanco de Dados
, as the only thing to be done as this list is to go through the same, so there is no need for aList<listaDependentes>
, but this is just a micro-timization, so you don’t have to worry about this.– Tobias Mesquita
Okay, thank you...
– Marco Souza
@Marconciliosouza added a note about accessing the Dates.
– Tobias Mesquita
Good tip, didn’t know this one.
– Marco Souza
Only one correction, the right is . Tostring("dd/MM/yyyy"), with mm returns 00. ie 17/00/2016
– Marco Souza