I have a table, where I only write scripts . There is a field, where I separate whether it is technical script or central script. There is a TipoScript
field that char is "C" or "T". This table was not well done without thinking about the future, so we have the NomeScript
field, which always has the same name for script Técnico
and the same name for Central script. p>
My query should return both scripts , but I'll have to differentiate between them. I confess I do not know how to do this. I could put it like this: tecnico = sc.scripttecnico
, but the only way to know is by field TipoScript
and name field as I did above, has given stick.
Could anyone suggest me how to do this? It can be in lambda as well.
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 this, but it gives an error 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();