I have a web api that is setup with asp.net identity that is using the default VS15 template and a "defaultconnection" connection string. I added a class library to the solution and on that I added an entity framework ado.net model from my database. I added a connection string that was in the class library's app.config file to my web config.
Web.config connection strings on api:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=MyDatabase;Initial Catalog=Dev;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="IBPC_DevEntities" connectionString="metadata=res://*/IBPCDataModel.csdl|res://*/IBPCDataModel.ssdl|res://*/IBPCDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MyDatabase;initial catalog=Dev;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
For a test I'm trying to do a get request for user info from my api's controller:
[Authorize]
public HttpResponseMessage Get(int id)
{
using (IBPC_DevEntities entity = new IBPC_DevEntities())
{
return Request.CreateResponse(HttpStatusCode.OK,
entity.User.FirstOrDefault(u => u.NDBHUserID == id));
}
}
When I send the request in Postman (with the authorization token) It responds with an InnerException that says "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."
How can I use database first EF6 in it's own project and reference it from my API that's using defaultconnection to authenticate?