У меня есть следующий собственный запрос SQL:
select
a.id_agente,
a.alias,
a.direccion,
cd.description,
( select te.data
from tevento te
left join tagente ta on ta.id_agente = te.id_agente
where ta.id_agente = a.id_agente order by timestamp desc limit 1
) as data
from tagente a
left join tagent_custom_data cd on a.id_agente = cd.id_agent
where cd.id_field = 6 and cd.description = $VAR;
У меня есть этот запрос в ядре .net в контроллере, подобном этому:
[HttpGet]
public ActionResult<string> GetAgentesByPlanta(string idPlanta)
{
using (var db = new MyContext())
{
List<Object> lst = new List<Object>();
var q =
from a in db.Agente
join cd in db.CustomData on a.id_agente equals cd.id_agent
where ((cd.id_field == 6) & (cd.description == idPlanta))
select new { Agente = a, CustomData = cd };
foreach (var x in q)
{
lst.Add(new {
id_agente=x.Agente.id_agente,
nombre=x.Agente.nombre,
direccion=x.Agente.direccion,
alias=x.Agente.alias,
ultimo_contacto=x.Agente.ultimo_contacto
});
}
dynamic response = lst;
return Ok(response);
}
}
Этот контроллер отвечает с помощью json иэто работает. Но, как вы можете видеть, подзапрос select отсутствует.
¿Как добавить подзапрос в этот запрос .NET Core?