Update: This is not a web application; it's a server service which has a lot of DLL's that access the DB in different ways. I needed a way to have a singleton entity framework DLL that could provide the access to the DB.
I'm attempting to setup a DAL DLL object utilizing Entity Framework 6 within my project. I want to call a single object versus setting up the model within all of the objects that need it. That way I can update the data model in one place and all of my libraries will be updated as well.
So within my project I created a .NET framework project and linked to the database to create the model (DB first). So that project sees the model ok.
I can then link to the DLL object's model within one of my other projects within the solution by creating a reference to the project and linking to the created entity like this:
ModelEntities db = new ModelEntities();
I can see all of the methods and objects that were created. But it seems I cannot access the DB when I run a very simple query like:
var dbRecord = (from record in db.UserKey).FirstOrDefault();
I can create a test within the entity model class and run that above query with no issues. And when I examine the db object, it looks like it's initialized.
Then thinking about it, I'm not sure the entity model is logged into the SQL Server using the outside object and that theory seems verified when I step through the code, the db object in that case has a bunch of exceptions on it even before running the query.
I'm not even sure I'm going about this right in the first place; that could definitely be a possibility. But in the case that I am right, how can I initialize the DB connection in the remote entity class before I call the query?