Reputation: 121
I'm learning ASP MVC5 and EntityFramework seems to "silently crash" (I know I'm to blame).
I started a new project from the template and added a table [People] to the template database linked to the default connection string in my webconfig:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WorstPeople.WebUI-20141007014802.mdf;Initial
Catalog=aspnet-WorstPeople.WebUI-20141108014803;Integrated Security=True" providerName="System.Data.SqlClient" />
I then added a new domain class library project, that includes with a repository pattern? (still learning). I have Ninject and Moq.
My view lists every Person in my database (example: return View(repository.People); ). The view works properly if I bind a Mock repository to my DI. However, if I bind it to my EntityFramework context, it returns an empty list instead of an error (and my database has data).
Questions :
Shouldn't EntityFramework (or something) give me an error when it's unable to connect to my [People] table?
Does attaching a .mdf file prevent IIS from launching and EntityFramework from working properly?
As part of the project template MVC5 creates, is there a "database" that launches IIS, or is it only a database file? I don't know much about IIS or databases.
Out of curiosity: Is it bad to store your domain within the same database as your user? I am trying this out to have only 1 database, but I was wondering.
EDIT :
I noticed I get the same empty result if I modify my class name to Person2, which leaves me thinking "How do you find an error when there's no way to understand where it lies"
Upvotes: 0
Views: 1280
Reputation: 44600
Upvotes: 1
Reputation: 121
I found out that changing my Connection's name from "DefaultConnection" to "EFDbContext", which is the same as my derived DbContext object, solves the problem.
I'm guessing Entity Framework works by connection a derived DbContext object with an equally named connection name.
Is there any further insight or tips I should consider on the subject?
Upvotes: 0