DbContext has been disposed
Your context has been disposed somewhere else (not in the code you've shown), so basically when you access it from your Register
action, it throws the exception.
Actually, you shouldn't use a static singleton to access to your context. Do instantiate a new DbContext
instance for each request. See c# working with Entity Framework in a multi threaded server
In my case, my GetAll method was not calling ToList() method after where clause in lambda expression. After using ToList() my problem was solved.
Where(x => x.IsActive).ToList();
You are probably 'lazy-loading' a navigation property of User
in your registration view. Make sure you include it by using the Include
method on your DbSet
before sending it to the view:
_db.Users.Include(u => u.PropertyToInclude);
Also, sharing DbContext
s with a static property may have unexpected side effects.