I have my MVC project in one assembly and the Data Project which Contains the DbContext Class in another assembly with Entity/Model class being another in the same solution.
Whenever I try to create a View with Scaffolding with the DbContext menu selecting the DbContext inherited class I get this run time error :
There was a problem running the selected code generator "Object reference not set to an instance of an object"
Controller Class :
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(string username, string password)
{
return View();
}
}
DbContext Class :
public class BlogDbContext : DbContext
{
public DbSet<Login> Logins { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<Permission> Permissions { get; set; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<BlogCatagory> BlogCatagories { get; set; }
public DbSet<BlogType> BlogTypes { get; set; }
public DbSet<Comment> Comments { get; set; }
public BlogDbContext() :base("name=MVPDB")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
Now suppose, I want to create a View for the Login with Edit and selected the DbContext class I get a window popping up saying :
There was a problem running the selected code generator "Object reference not set to an instance of an object"