I have a solution, which consists of several projects.
1. Persistence
, where I have class Repository that gets data from database, and class MyDbContext
2. API
where controller takes repository class as a dependency.
3. MVC
, where controller sends request to API and gets data and sends it to view
So, the SQLite database file is located in the API project. But now I need to work with the database using a repository not from API project, but right from MVC project (I know, it doesn't correspond with the architecture of my project, but still I want to do that).
But if I use repository class in the MVC project, it creates a new database in the MVC project, but I need to use the database file which is in API project. And it happens even if I add repository in both projects as singleton.
How can I use the same database from the MVC project as well?
I solved it, I needed to modify the path to the database to this:
Data Source=../PollsApp.Api/data.db
I am not sure why are you trying to use one data source for separate projects, unless they need to handle the same data (located in the same DB), and it is not just to cut corners and not create separate database just because :)
So, I could suggest specifying everywhere absolute path to the file with the SQLite database, something like:
Data Source=C:/temp/PollsApp.Api/data.db
I also would strongly recommend moving the database file outside of any project, to prevent it being moved accidentaly with the containing project.