I have a query in linq that returns a list of colonies from a table in SQLSERVER.
var todasColonias = (
from SQLColonias in context.colonias
where SQLColonias.status.Equals(true)
select new
{
_idColonia = SQLColonias.id_colonia,
_tipoAsentamiento = SQLColonias.tipo_asentamiento,
_descrColonia = SQLColonias.descripcion
}
).ToList();
I need to concatenate the value of the field _typeAssembly when the value of the field _descrColonia exists duplicated in any other record.
In summary, I need to do something like this:
var todasColonias = (
from SQLColonias in context.colonias
where SQLColonias.status.Equals(true)
select new
{
_idColonia = SQLColonias.id_colonia,
_tipoAsentamiento = SQLColonias.tipo_asentamiento,
_descrColonia = (SQLColonias.descripcion Existe en cualquier otro registro) ? (_tipoAsentaiento + SQLColonias.descripcion) : (SQLColonias.descripcion)
}
).ToList();
The intention is to obtain something like this in the field _descrColonia:
_descrColonia = "HAMBURGO"
_descrColonia = "SANTA ROSA"
_descrColonia = "SAN ANTONIO"
_descrColonia = "(FRACCIONAMIENTO) LA ROSITA"
_descrColonia = "(AMPLIACION) LA ROSITA"
_descrColonia = "CENTRO"
_descrColonia = "LOS ANGELES"
In this example the value "LA ROSITA" exists in multiple registers, so the string corresponding to the field _TypeAsentamiento is concatenated.
I know I can go through the list later and apply the concatenation based on techniques such as group () or contains (), but when I tried it I noticed the slowness, so I would prefer to do it directly from the select, is it possible ?