Note that there are some explanatory texts on larger screens.

plurals
  1. POThe context cannot be used while the model is being created
    primarykey
    data
    text
    <p>I'm getting a problem with my entity framework usage and think it could be because I'm using my DB context incorrectly.</p> <p>Every now and then I'm seeing error messages in my log stating: "The context cannot be used while the model is being created."</p> <p>The error doesn't always occur and seems to be on a fresh application load or if I compile my project and refresh a browser tab whilst it's compiling.</p> <p>The function below is the one that is error'ing and is called from my master page.</p> <pre><code>public static class UserFunctions { private static peopleSwimmingContext _db = new peopleSwimming.Models.peopleSwimmingContext(); public static String GetUserRole(Int32 UserID) { String returnedRole = String.Empty; var foundUser = _db.Users.Where(w =&gt; w.UserId == UserID).FirstOrDefault(); if (foundUser != null) { returnedRole = foundUser.Role.Name; } return returnedRole; } } </code></pre> <p>Any tips would be massively appreciated!</p> <p>Oh and here is my innerstack trace:</p> <p>Inner Stack Trace:</p> <p>at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet<code>1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet</code>1.get_InternalContext() at System.Data.Entity.Infrastructure.DbQuery<code>1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable</code>1 source, Expression`1 predicate) at peopleSwimming.Logic.UserFunctions.GetUserRole(Int32 UserID) in c:\svn\peopleSwim\peopleSwimming\Logic\UserFunctions.cs:line 18 at peopleSwimming._Home.Page_Load(Object sender, EventArgs e) in c:\svn\peopleSwim\peopleSwimming\Home.aspx.cs:line 25 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload