huyrua / efprs

Entity Framework POCO, Repository and Specification Pattern
MIT License
40 stars 18 forks source link

WebDbContextStorage in intergrated mode not working #2

Closed pmdevers closed 11 years ago

pmdevers commented 11 years ago

Could you please help me with the following issue.

I have a web application using EF5 Code First with your Repository Pattern. But when using the WebDbContextStorage like this in the Application_Start()

DbContextManager.Init("Default"); DbContextManager.InitStorage(new WebDbContextStorage(this));

When the app pool is running in Integrated Mode i recieve the following error message.

Object reference not set to an instance of an object.

when running in classic mode it is working fine.

When switching back to SimpleContextStorage it is also working fine for a single user.

huyrua commented 11 years ago

Instead of initialize DbContext in Application_Start, try it in Init(). Also, you need to create an private instance WebDbContextStorage inside MvcApplication (Global.asax.cs):

public class MvcApplication : System.Web.HttpApplication { // other code...

private WebDbContextStorage _storage;
public override void Init()
{
    base.Init();
    _storage = new WebDbContextStorage(this);
}

protected void Application_BeginRequest(object sender, EventArgs e)
{
    DbContextInitializer.Instance().InitializeDbContextOnce(() =>
    {
        DbContextInitializer.InitStorage(_storage);
        DbContextInitializer.Init(new[] { Server.MapPath("~/bin/[mapping-assembly-name].dll") });
    });
}

// other code...

}

pmdevers commented 11 years ago

Yes thanks that was it Great Work