Here is part of my Hardware class:
public class Hardware
{
public int Id { get; set; }
public virtual ICollection<HardwareType> HardwareType { get; set; }
....
}
In the sample data that is seeded, Hardware is newed up like this (partially):
new Hardware { ... HardwareType = htype.Where(h => h.HType == "PC").ToArray() }
htype
is a List<HardwareType>
with various string values for HType
, which is the property in the HardwareType
class.
In my controller, I am trying to assign a Lambda expression to a variable so I can loop through it in my view. Here is what I have:
private Context db = new Context();
public ActionResult Index() {
Hardware Pcs = db.Hardware.Where(h => h.HardwareType == "PC");
}
But the compiler is telling my I can't do that because h.HardwareType
is an iCollection. Which makes sense. But how do I write this line of code so that I can pass Pcs
to my view?