Filtering result by category

Asked

Viewed 34 times

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 it returns me all products. I do not know how to use Where to filter my result by category.

1 answer

1


There is not much secret, just know which field you will use to filter. Assuming you have an Idcategoria is either filter by Idcategoria = 1 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;

  1. The query will only be executed when it is in the foreach interaction, then until then you can manipulate it with more filters.
  2. Remember to use the Namespace System.Linq
  • Gave error Error 2 Delegate 'System.Func<Microsoft.Samples.Kinect.InteractionGallery.products,int,bool>' does not take 1 Arguments E: Usuario Documents Visual Studio 2012 Clean Showcase Views Articleview.xaml.Cs 54 45 Showcase

  • managed to resolve ?

  • Yes I did, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.