title: What am i doing wrong? : Context Cannot be used while the model is being Created
body: <p>I'm stucked with this problem and i've spent more than 3 hours scouring the web and SO for a solution to no avail. My Code keeps throwing this error </p>
  
  <blockquote>
    <p>The context cannot be used while the model is being created. This
    exception may be thrown if the context is used inside the
    OnModelCreating method or if the same context instance is accessed by
    multiple threads concurrently. Note that instance members of DbContext
    and related classes are not guaranteed to be thread safe.</p>
  </blockquote>
  
  <p>This is my Context</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("DefaultConnection")
      {
      }
      public DbSet&lt;ApprovalStatus&gt; ApprovalStatuses { get; set; }
      public DbSet&lt;Bank&gt; Banks { get; set; }
      public DbSet&lt;Documents&gt; Documents { get; set; }
      public DbSet&lt;EducationLevel&gt; EducationLevel { get; set; }
      public DbSet&lt;EmploymentDetail&gt; EmploymentDetails { get; set; }
      public DbSet&lt;EmploymentStatus&gt; EmploymentStatus { get; set; }
      public DbSet&lt;Gender&gt; Genders { get; set; }
      public DbSet&lt;GuestPersonalDetail&gt; GuestPersonalDetails { get; set; }
      public DbSet&lt;LGA&gt; LocalGovts { get; set; }
      public DbSet&lt;LoanDetail&gt; LoanDetails { get; set; }
      public DbSet&lt;MaritalStatus&gt; MaritalStatuses { get; set; }
      public DbSet&lt;NameTitle&gt; NameTitles { get; set; }
      public DbSet&lt;NextOfKin&gt; NextOfKins { get; set; }
      public DbSet&lt;RejectionReasons&gt; RejectionReasons { get; set; }
      public DbSet&lt;RepaymentMode&gt; RepaymentModes { get; set; }
  }
  </code></pre>
  
  <p>in my controller i have this where i try to populate a dropdownlist in my view</p>
  
  <pre><code>[HttpGet]
  public ActionResult Apply()
  {
      var db = new ApplicationDbContext();
      ApplicationVM model = new ApplicationVM();
          model.BankList = new SelectList(db.Banks, "Bankid", "BankName");
          model.EducationLevellist = new SelectList(db.EducationLevel, "EducationLevelid", "Level");
          model.EmploymentStatuslist = new SelectList(db.EmploymentStatus, "EmploymentStatusid", "EmpStatus");
          model.GenderList = new SelectList(db.Genders, "Genderid", "GenderVal");
          model.LGAlist = new SelectList(db.LocalGovts, "LGAid", "LgName");
          model.MaritalStatusList = new SelectList(db.MaritalStatuses, "MaritalStatusid", "Status");
          model.NameTitleList = new SelectList(db.NameTitles, "NameTitleid", "Title");
          model.RepaymentModeList = new SelectList(db.RepaymentModes, "RepaymentModeid", "ModeOfRepayment");
          return View(model);           
  }
  </code></pre>
  
  <p>i used this in view like this</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.ApplicantTitleid, new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownListFor(model =&gt; model.ApplicantTitleid, Model.NameTitleList, null, String.Empty)
          @Html.ValidationMessageFor(model =&gt; model.ApplicantTitleid)
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The error is being thrown at the Dropdownlistfor point. This is the stack trace</p>
  
  <pre><code>[InvalidOperationException: The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.]
     System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +115
     System.Data.Entity.Internal.InternalContext.Initialize() +31
     System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39
     System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +138
     System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +38
     System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable&lt;TResult&gt;.GetEnumerator() +108
     System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +157
     System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
     System.Linq.Enumerable.ToList(IEnumerable`1 source) +133
     System.Web.Mvc.MultiSelectList.GetListItemsWithValueField() +461
     System.Web.Mvc.MultiSelectList.GetListItems() +89
     System.Web.Mvc.MultiSelectList.GetEnumerator() +39
     System.Web.Mvc.Html.SelectExtensions.GetSelectListWithDefaultValue(IEnumerable`1 selectList, Object defaultValue, Boolean allowMultiple) +557
     System.Web.Mvc.Html.SelectExtensions.SelectInternal(HtmlHelper htmlHelper, ModelMetadata metadata, String optionLabel, String name, IEnumerable`1 selectList, Boolean allowMultiple, IDictionary`2 htmlAttributes) +574
     System.Web.Mvc.Html.SelectExtensions.DropDownListHelper(HtmlHelper htmlHelper, ModelMetadata metadata, String expression, IEnumerable`1 selectList, String optionLabel, IDictionary`2 htmlAttributes) +56
     System.Web.Mvc.Html.SelectExtensions.DropDownListFor(HtmlHelper`1 htmlHelper, Expression`1 expression, IEnumerable`1 selectList, String optionLabel, IDictionary`2 htmlAttributes) +233
     System.Web.Mvc.Html.SelectExtensions.DropDownListFor(HtmlHelper`1 htmlHelper, Expression`1 expression, IEnumerable`1 selectList, String optionLabel, Object htmlAttributes) +142
     ASP._Page_Views_Loan_Apply_cshtml.Execute() in c:\Users\RIDWAN\Documents\visual studio 2013\projects\ApplicationPortal\ApplicationPortal\Views\Loan\Apply.cshtml:37
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
     System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +120
     System.Web.WebPages.StartPage.RunPage() +63
     System.Web.WebPages.StartPage.ExecutePageHierarchy() +100
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
     System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
     System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
     System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass28.&lt;BeginInvokeAction&gt;b__19() +321
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1e.&lt;BeginInvokeAction&gt;b__1b(IAsyncResult asyncResult) +185
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
     System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
     System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +39
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +932
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +188
  </code></pre>
  
  <p>What am i doing wrong exactly?</p>