0
I have a chart, where I only record scripts. There is a field, where I separate whether it is technical script or central script. There is a field TipoScript
char e is "C" or "T". This table was not well made, without thinking about the future, so we have the field NomeScript
, that always has the same name for script Técnico
and the same name for Central script.
My consultation should return both scripts, but I’ll have to differentiate between the two. I confess I don’t know how to do it. I could put it like this: tecnico = sc.scripttecnico
, but the only way to know is through the countryside TipoScript
and name field as I did above, has given dick.
Could anyone suggest me how to do that? It might be on lambda also.
This is my LINQ:
public TPDV getCnpjParceiro(string cnpj)
{
WEBEntities db = new WEBEntities();
TPDV pdv = new TPDV();
List<string> lista = new List<string>();
var resultado = (from _lista in db.T_PDV
where _lista.CNPJ == cnpj
join _st in db.T_CRM_StatusPDV on _lista.CNPJ equals(_st.DE_Cnpj)
join _sc in db.T_Script on _st.IT_Status equals((int)_sc.TipoStatus)
select new
{
_lista.CNPJ,
_lista.RazaoSocial,
_lista.Endereco,
_lista.CaminhoLogo,
_lista.Bairro,
_lista.Cidade,
_st.IT_Status,
_st.DT_TransacaoV,
_sc.Script
}).ToList();
foreach (var lis in resultado)
{
pdv.CNPJ = lis.CNPJ;
pdv.RazaoSocial = lis.RazaoSocial;
pdv.Endereco = lis.Endereco;
pdv.CaminhoLogo = lis.CaminhoLogo;
pdv.Bairro = lis.Bairro;
pdv.Cidade = lis.Cidade;
}
return pdv;
}
I tried to do it like this, but it makes a mistake in technical and central
var resultado = (from _lista in db.T_PDV
where _lista.CNPJ == cnpj
join _st in db.T_CRM_StatusPDV on _lista.CNPJ equals(_st.DE_Cnpj)
join _sc in db.T_Script on _st.IT_Status equals((int)_sc.TipoStatus)
select new
{
_lista.CNPJ,
_lista.RazaoSocial,
_lista.Endereco,
_lista.CaminhoLogo,
_lista.Bairro,
_lista.Cidade,
_st.IT_Status,
_st.DT_TransacaoV,
tecnico = _sc.TipoScript == "T" ? _sc.Script : null,
central = _sc.TipoScript == "C" ? _sc.Script : null
}).ToList();
Is making a mistake ?
– user6026