Reputation: 11430
I am writing an application that will access a local database (MS Access) as a cache for a remote SQL server.
I have a "logic" project and a "UI" project. The .accdb file in currently in the UI project and build action set to content, copy if newer. However, this somehow feels really wrong but I am not sure what is the correct systematic way handling it.
Should I create a database project? But honestly, I am quite clueless when it comes to database projects and not sure where to starting learning. Also, the options available in visual studio seems to only be SQL based.
I am thinking maybe I should create a new project, put .accdb as content and to the project add code for version upgrades, migration, schema updates which currently isn't any where in the solution.
Which way should I head?
Upvotes: 1
Views: 710
Reputation: 1155
In the interest of creating clean separation of responsibilities, put your data access somewhere other than you UI project; i.e. in a separate project. Your UI project will then use the data access project to perform relevant data actions.
Extract an interface (IDataAccess or something) that your UI project knows about and your data access project implements. You can put the interface in another project (call it ShareInterfaces for example) that your UI code references and your data access project references and implements. You can then use Dependency Injection in your UI code to get the implementation of the IDataAccess.
There are lots of open source dependency injection (or IoC as it is sometimes known) frameworks out there. I have used Ninject previously, and it works very well for simple cases - no need to XML configuration, you can do all your binding declaratively in code.
The dependency injection is not essential but it does provide a nice way to decouple dependencies in your code and make your code unit testable.
Upvotes: 1
Reputation: 94645
I think you should have to use the default option: Copy To Output Directory=copy if newer'
this way the build will copy that file whenever you build your project.
Upvotes: 2