Reputation: 15
I'm developing a desktop application in C# supporting MySQL and I'm having the following questions
1) Is it possible develop one version of app that will support different databases according customer's needs? What I mean is what if I want to give to someone the app for testing purposes supportind an Access DB or install the app to a customer that he already has MySQL or SQL installed
2) If the above is true how can I achieve it?
Upvotes: 1
Views: 1559
Reputation: 5357
You can use the Entity Framework (via Code First) for your database layer code, which can be configured in the applications app.config to be used with MS Sql Server, Sql Compact Edition, Sql Express, MySql, and SQLite, and possible others.
The're blogs on getting EF working with PostreSQL as well, but I wouldn't recommend supporting it, it's tedious and hit or miss.
Alternatively, you could use PetaPoco (A Micro ORM), which also support different data providers, but you still have to write Select Queries yourself, which would entail writing the write SQL Query for the active dataprovider.
Entity Framework writes all the SQL for you using Providers for Entity Framework which include SQL Query Generators.
However, depending on the nature of your application I would recommend just using SQLite 100%. You can embed it in your application without requiring them to install database server software at all. Then you can rely on PetaPoco or your own Data Layer without worrying about SQL Query conversions, and differences in the database servers.
I would recommend going NoSql, but in my opinion, none of the free NoSql solutions (that I am aware of) are very viable right now on the .Net Platform.
In terms of being able to support (many database servers) without having to manage any code yourself to do it, Entity Framework is probably the best solution.
Before you shoot down Entity Framework though, consider the fact that you can use CodeFrist which will generate the database and perform upgrades on it for you automatically. E.g. you create Entities that define your tables and the columns on them (which can inherit from each other to reuse column name/types on other tables). And you can create Migration Classes that define a new version with changes so you can have it automatically Migrate Version X.1 of your database to X.9, etc. It's very handy.
Upvotes: 0
Reputation: 51
Manos,
It is feasible ,your app will work like for all the databases . But,if they have different versions of MySQL Server like 5.1,5.5,5.6 needs to change some database and application code level changes .
Upvotes: 0
Reputation: 60518
Yes. .NET has a Data Provider Factory (DbProviderFactory) that you can use to support multiple databases.
I have a blog post here:
http://blogs.msmvps.com/deborahk/dal-using-a-data-provider-factory/
It provides a code example.
Upvotes: 2