Please, I am stuck with this challenge for some hours now. Don’t know where I am getting this wrong.
I have two entities; service_catalog and services. I have a foreign key on services which has a reference to service_catalog. So the idea is that, a service_catalog has many services.
I am trying to get a list of all services based on the service_catalog name passed from the combobox. But I get a null exemption on the serviceList variable. But when I test with a message box, it gave me the id which I taught I could use. But I get the error.
Here is my code. Will appreciate any assistance.
//Get catalog name
private service_catalog GetName(string sCatalogname)
{
    using (Model db = new Model())
    {
        return db.service_catalog.FirstOrDefault(s => s.name == Catalogname);
    }
}
//Load the services based on the service_catalog selected
private void comboBoxServices_SelectedIndexChanged(object sender, EventArgs e)
{
    service_catalog data = GetName(comboBoxServices.Text);
    List<service> serviceList;
    if (data != null)
    {
        serviceList = dbHelper.services.Where(s =>s.service_catalog_id == data.service_catalog_id).ToList();
        dataGridViewServices.DataSource = serviceList;
    }
}
Error Thrown: {"Object reference not set to an instance of an object."} This line:
serviceList = dbHelper.services.Where(s => s.service_catalog_id == data.service_catalog_id).ToList();
I appreciate any assistance.
EDIT
from the comment of the OP
serviceList object count is 0 while data object shows
"{System.Data.Entity.DynamicProxies.service_catalog_BF9EC14C144A9AC84B6F0CB43564996B60E8EA5EA9C2B7D58C0BBE5AE20FC83B}"
 
    