This is my code:
private List<Picture> items;
public List<Picture> Items
{
get
{
if (items == null)
{
items = new List<Picture>();
items = this.LoadAllItems();
}
return items;
}
set
{
this.items = value;
}
}
public List<Picture> GetItemsBySearch(string searchTerm, string fieldName)
{
DataAccess dbcontext = new DataAccess();
string internalfield = dbcontext.GetInternalFieldNameByDisplayName(fieldName);
List<Picture> PictureHits = new List<Picture>();
var data = from Picture item in this.Items
where item.GetType().GetProperty(internalfield).GetValue(item, null).ToString().Contains(searchTerm)
select item;
foreach (Picture item in data)
{
PictureHits.Add(item);
}
return PictureHits;
}
The data.Count contains 88 items but it does not enter a foreach loop.
Does the var not work within a foreach loop?
Picture is a class with some objects like filename, ID, etc.
This is what "data" contains so it contains 88 items doesnt it?

from Picture item in this.Items??? should befrom item in this.Itemsitems = new List<Picture>();in the getter is useless. You can just remove it.Items. Data has no Count property.PictureHits = data.ToList();PictureHits Count is 0 Maybe my where is not working?