Show certain data in a column

0

I have my next table called LIST with two columns: Id, and Name, in the Name column I have 4 data: Notes, Agenda, Authorization and Membership.

 public IQueryable Listar1()
    {

        return from titus1 in Contexto.LISTA



               select new
               {
                   titus1.Nombre

               };
    }

But I just want to show the Calendar and Membership data, from the Name column.

    
asked by SoyKrut 25.11.2017 в 17:41
source

1 answer

1

If you want to get the two records that have that data you can do the following:

return from titus1 in Contexto.LISTA
       where titus1.Nombre == "Agenda" || titus.Nombre == "Membresia"
           select new
           {
               titus1.Nombre

           };

or the "functional" form (I leave it as an option):

return Contexto.LISTA
    .Where(x => x.Nombre == "Agenda" || x.Nombre == "Membresia")
    .Select(new { titus1.Nombre});

Now, if you only want the data that has the name column, I would leave it like this:

return from titus1 in Contexto.LISTA
       where titus1.Nombre == "Agenda" || titus.Nombre == "Membresia"
           select titus.Nombre;

That would return only the content of the Name field, basically a list of type string with two elements. It depends on how you want to use the data in the query.

    
answered by 25.11.2017 / 18:47
source