Reputation: 2037
I'm following the book EF Code First by Lerman, and one of the things you do in the book is create a class library project in which you define a class that will inherit from DbContext. For this, you need to install Entity Framework. When you do this, two files will be added: App.config and packages.config.
Then you add a console project, and use your brand new context class in a using statement. You'll encounter quite some errors, because the Console Project does not have a reference to EntityFramework.dll and EntityFramework.SqlServer.dll, and also because I'm not using SQL Server Express, but a full version.
Now there are two options. The first is to also install entity framework in the console project. The other option is to reference the two .dll's, by adding a reference and adding them from the recent tab.
The first option will again add the App.config and packages.config files, but this time to the console project.
The second option does not. But trying to run the application will throw an exception, since it is looking for a connection string, and it can't find any. The solution I found is to copy the App.config that's in the class library project over to the console project, and put in a connectionString section in the copied App.config.
But this raises the question:
Which of these files can I remove? I seem to be able to remove the packages.config and App.config from the DataAccess project without any troubles. The console project seems to need the App.config.
Upvotes: 1
Views: 3328
Reputation: 93464
While you don't need the app.config in the library project per se if you're using code first (you do if you're using model or database first).. every time you add a project or do something that needs configuration, a new one will be added, so you might as well just keep it there.
You should keep the packages.config because this keeps track of the version of packages you have installed, so that you can more easily upgrade later.
If you're using database or model first, the designer needs the app.config to tell it the connection string to use.
Upvotes: 3