Filtering result by category

2
using (ObjectContext ctx = new ObjectContext("name=kinectEntities"))
{
    ctx.DefaultContainerName = "kinectEntities";
    ObjectSet<produtos> query = ctx.CreateObjectSet<produtos>();

    foreach (produtos r in query)
    {
        //percorrendo registros da base.. monta as parada aqui..
        var button = new KinectTileButton { Label = (r.valor).ToString(CultureInfo.CurrentCulture) };
        this.wrapPanel.Children.Add(button);
    }
};

I have this code only that it returns me all products. I do not know how to use the where to filter my result by category.

    
asked by anonymous 14.09.2017 / 21:36

1 answer

1

There is not much secret, just just know which field you will use to filter. Assuming you have a CategoryID that either filters by CategoryID = 1 it would look like this;

var prodtutos = query.Where(p => p.IdCategoria == 1);

Your query can be done like this;

using (ObjectContext ctx = new ObjectContext("name=kinectEntities"))
{
    ctx.DefaultContainerName = "kinectEntities";
    ObjectSet<produtos> query = ctx.CreateObjectSet<produtos>();

    var prodtutos = query.Where(p => p.IdCategoria = 1);

    foreach (produtos r in prodtutos)
    {
        //percorrendo registros da base.. monta as parada aqui..
        var button = new KinectTileButton { Label = (r.valor).ToString(CultureInfo.CurrentCulture) };
        this.wrapPanel.Children.Add(button);
    }
};

Details;

  • The query will only execute when you have the foreach interaction, so by then you can manipulate it with more filters.
  • Remember to use the System.Linq Namespace
  • 14.09.2017 / 21:43