I really suck at LINQ statements, so if someone could help me find a way to consolidate these two statements, I would be forever grateful:
public IList<SomeType> getSomeTypes(string id){
string itemName = (from item in _itemcollection
where item.id.Equals(id)
select item.name).FirstOrDefault();
return (from item in _itemcollection
item.name == itemName
select item)
.ToList();
id is a unique id, and this is _itemcollection is an IQueryable.
The goal is to get the Name of the item that matches the id (which is unique), then find all the items that have the same name (of which there are many).
1 Answer