Data Access from Entity framework works during debugging but not on live

Viewed 1502

I got unique situation in my Entityframework web application, I'm trying to load the fields in page through list but its keep saying "The objectContext insteance has been disposed and can no longer be used for operations that require a connection." But when I set the debugging point and step into to see what is the error it works fine??

Here is my codes: This is Under my Page Load Event...

private void loadGPYouth()
{
  List<GPYouth> leader = GPYouthLoader.getGPYouth(ViewState["LeaderID"].ToString());
   foreach (var item in leader)
   {
   ddlConstituency.SelectedValue = item.Grampanchayat.ConstituencyID.ToString();
   ddlMandal.SelectedValue = item.Grampanchayat.MandalID.ToString();
   //filling remaing fields.....
   }
}

This is under GPYouthLoader class :

public static List<GPYouth> getGPYouth(string LeaderID)
{
  List<GPYouth> list = new List<GPYouth>();
  using (var db = new TDPMADANEntities())
  {
   int _id = Convert.ToInt32(LeaderID);
   var query = (from b in db.GPYouths where b.YouthID == _id select b).ToList();
   list = query.ToList();
  }
  return list;
}

And This is my GPYouth class :

public partial class GPYouth
{
    public long YouthID { get; set; }
    public Nullable<long> GPID { get; set; }
    //Remaining Fields....
    public virtual Grampanchayat Grampanchayat { get; set; }
}
2 Answers
Related