Question

I'm trying to generate views, because the performance using Code First is super slow until it caches. Taking ~10 seconds to load the web page the first time until it caches. Unfortunately, I'm getting an error when I right click my Context object and try to Generate Views. The error I'm getting is "Object reference not set to an instance of an object." I assume I'm missing something. Here is my context code, let me know if you want to see my Entities as well:

public class BulletinBoardContext : DbContext
{
    public BulletinBoardContext() : base("BulletinBoardContext")
    {
        this.Database.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["BulletinBoardContext"].ConnectionString;
        this.Configuration.LazyLoadingEnabled = false;
        this.Configuration.ProxyCreationEnabled = false;
    }

    public DbSet<Category> Categories { get; set; }
    public DbSet<Image> Images { get; set; }
    public DbSet<Post> Posts { get; set; }
}
Was it helpful?

Solution

Remove this line:

this.Database.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["BulletinBoardContext"].ConnectionString;

This solves the whole problem. It is without any sense as passing connectionStringName to base constructor as you do in your code should already properly assign connection string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top