Get data from an array with LINQ

0

If arrRep is an array I can perform the following query with linq are the arrRep array, I want the references that meet the condition of the query:

arrRep = oRep.buscarTodosImpo(dFecIni, dFecFin, nDato);

var q = (from f in arrRep
           where f.Arribo == "2017-01-01" || f.Revalidacion == "2017-01-01" || f.Previo == "2017-01-01" || f.Desadua == "2017-01-01" || f.EnvioFact == "2017-01-01"
                                 select f.Referencia).ToList();



public class ReporteGeneralImpo
{
    private string ejecutivo = "";

    public string Ejecutivo
    {
        get { return ejecutivo; }
        set { ejecutivo = value; }
    }
    private string referencia = "";

    public string Referencia
    {
        get { return referencia; }
        set { referencia = value; }
    }
    private string pedimento = "";

    public string Pedimento
    {
        get { return pedimento; }
        set { pedimento = value; }
    }
    private string tipoCarga = "";

    public string TipoCarga
    {
        get { return tipoCarga; }
        set { tipoCarga = value; }
    }
    private int tCont = 0;

    public int TCont
    {
        get { return tCont; }
        set { tCont = value; }
    }
    private string arribo;

    public string Arribo
    {
        get { return arribo; }
        set { arribo = value; }
    }
    private string revalidacion;

    public string Revalidacion
    {
        get { return revalidacion; }
        set { revalidacion = value; }
    }
    private string previo;

    public string Previo
    {
        get { return previo; }
        set { previo = value; }
    }
    private string desadua;

    public string Desadua
    {
        get { return desadua; }
        set { desadua = value; }
    }
    private string envioFact;

    public string EnvioFact
    {
        get { return envioFact; }
        set { envioFact = value; }
    }

    private string cliente = "";

    public string Cliente
    {
        get { return cliente; }
        set { cliente = value; }
    }
}
    
asked by gcosquilla 10.10.2017 в 20:28
source

1 answer

0

Regards

Personally, I prefer to use it in the following way:

var q = arrRep.Where(w => w.Arribo.ToString("yyyy-MM-dd")=="2017-01-01"
            || w.Revalidacion.ToString("yyyy-MM-dd")== "2017-01-01" 
            || w.Previo.ToString("yyyy-MM-dd") == "2017-01-01" 
            || w.Desadua.ToString("yyyy-MM-dd") == "2017-01-01" 
            || w.EnvioFact.ToString("yyyy-MM-dd") == "2017-01-01")
          .Select(s => s.Referencia).ToList();

The above assumes that Arrival , Revalidation .... are elements of type Date .

I hope you find it useful.

Luck.

  

EDITED

Regarding the ToString error that you mention, each property is a String ; as it does not know the types of data, so I put you The above assumes that [...] they are elements type Date .

Regarding the new error that you indicate of the observed, I do not find that it can be generating it; You should check your side that causes it, at least what I put and see you have to filter the data is correct. If it is when assigning to var q = [.....]; or another part sees if you can obtain more detail of the error that allows to identify its origin; in case the error is not in var q = ....; verify the error (more details) may be due to a treatment you are doing; Remember that q (for your case) is basically a List<string> that can be empty or have 1 or more elements.

    
answered by 10.10.2017 в 20:40