I have two projects in myVS 2015 solution.
Project A
- Web Api 2.2 Project
- Main Project where DBContext class and connection string (in web.config file) is defined
Project B
- Class Library Project
- Project A added as a reference
- Models & Controller Defined
- Models inherits a class of Project A
- Created a DBContext class which inherits DBContext from Project A.
- public DbSet Planets { get; set; }
My idea behind the above project structure is:
To reduce the complexity when project grows larger
To make it less complex & increase the readability
To make Authentication & Authorization logic in Project A
I have to achieve following thing in Project B:
- Need to share/access connection string from Project A
- Need to run code first migration.
- Need to know how can I run the code first migration when deploying the application to prod?
Problem:
I have enabled code first migration and updated the DB. I'ts running without any issues but its not running against the database configured in web.config of Project A. Instead, its add its own local database.
Should I specify connection string in Project B as well. If yes, as its a class library how can I add a config file?