Мне нужна помощь с этой ошибкой "Экземпляр ObjectContext был удален и больше не может использоваться для операций, требующих подключения."
Это asp.net mvc3, EF4 и ms sql.Вот бритва с двумя выпадающими списками:
<div class="editRow">
@Html.DropDownListFor(m=>m.IndustryId, (SelectList)ViewBag.Industry, @Empower.Resource.General.ddlDefaultVal, new { @class = "ddl400" })
@Html.ValidationMessageFor(m => m.IndustryId)
</div>
<div class="editRow">
@Html.DropDownListFor(m=>m.ProvinceId, (SelectList)ViewBag.Province, @Empower.Resource.General.ddlDefaultVal, new {@class = "ddl400"})
@Html.ValidationMessageFor(m => m.ProvinceId)
</div>
Контроллер:
IndustryService indService = new IndustryService();
ViewBag.Industry = new SelectList(indService.GetAllIndustry(), "IndustryId", "IndustryName");
ProvinceService proService = new ProvinceService();
ViewBag.Province = new SelectList(proService.GetAllProvince(), "ProvinceId", "ProvinceName");
return View();
ProvinceService:
public IEnumerable<Province> GetAllProvince()
{
using (var context = DBContext.ObjectContext)
{
var pros = context.Provinces;
return pros;
}
}
IndustryService идентичен указанному выше ...
public class DBContext
{
private static EmpowerDBEntities _empowerContext;
public static EmpowerDBEntities ObjectContext
{
get
{
if (_empowerContext == null)
_empowerContext = new EmpowerDBEntities();
return _empowerContext;
}
}
}
Я знаю, что проблема возникает во втором раскрывающемся списке, когда он пытается извлечь данные, когда соединение прерывается предыдущим запросом.Пожалуйста, помогите мне с этим, спасибо.