Linq: How to filter a two dimentional array?

  • Thread starter Thread starter Sigurd F
  • Start date Start date
S

Sigurd F

Guest
Hei!
I got some Linq code to filter out an item with a special number, but I cant get the code return anything. Can someone help me?
I would appreciate if someone can explain how to use this "query" or point me toward a tutorial.


await _DataSource.GetDataAsync();
// Simple linear search is acceptable for small data sets
var matches = _DataSource.Categories.SelectMany(group => group.Items).Where((item) => item.ProdNo == selectedProdNo);
if (matches.Count() == 1) return matches.First();
return null;


{"Groups":[
{
"Category": "TRAINING",
"Title": "Training",
"Subtitle": "Group subtitle: 3",
"ImagePath": "ms-appx:///Assets/LightGray.png",
"Description" : "Group Description: Lorem ipsum dolor sit amet, consectetur.",
"Items":
[
{
"ProdNo": "621075",
"Title": "SVALESTJERT 3/4 TIGHTS",
"Subtitle": "Item Subtitle: 1",
"ImagePath": "ms-appx:///Assets/Products/621075_thmb_sea.png",
"Colors" : "sea,rock,berry",
"Description" : "The classic Wool Solid ski socks are comfortable and warm. Made out of a unique blend of merino wool and acrylic.",
"Content" : "Curabitur class aliquam vestibulum nam curae maecenas."
},
{
"ProdNo": "621391",
"Title": "TRUDE JACKET",
"Subtitle": "Item Subtitle: 1",
"ImagePath": "ms-appx:///Assets/Products/621391_thmb_green.png",
"Colors" : "green,npink",
"Description" : "Dummy tekst asdf asdf asdf as fas df.",
"Content" : "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus suspendisse quisque donec dis praesent."
}
]
}
]
}

public class Product {
public string ProdNo { get; private set; }
public string Title { get; private set; }
public string ImagePath { get; private set; }
public string Subtitle { get; private set; }

public Product(string prodno, string title, string imagepath, string subtitle)
{
this.ProdNo = prodno;
this.Title = title;
this.ImagePath = imagepath;
this.Subtitle = subtitle;
}

public override string ToString()
{
return this.Title;
}
}



public class Category
{
public string CategoryId { get; private set; }
public string Title { get; private set; }
public ObservableCollection<Product> Items { get; private set; }

public Category(string category, string title)
{
this.CategoryId = category;
this.Title = title;
this.Items = new ObservableCollection<Product>();
}

public override string ToString()
{
return this.Title;
}
}




Thanks, Sigurd F

Continue reading...
 
Back
Top