Can I use NHibernate as a standardized way to communicate with different database engines?
I just asked here if there was a general way to get tables names and created tables on a database.
I need this because my application connects to a database and 开发者_Python百科has some basic database edition functionality like creating tables with a wizard. But now I want the user to be able to select from a range of possible database engines (right now it only uses the Jet engine).
Most people told me this was not possible and that I would need to create an abstract layer with implementations for each database engine. But I just found NHibernate and it seems to me that it generates SQL queries for a wide range of database engine (I'm not sure if the Jet engine is included). So my question is, can I use NHibernate to achieve this?
Yes you can, as long as the database schema is the same across the different databases.
Here's a list of database engines supported by NHibernate (including Microsoft Jet) and the configuration settings required in order to work with them:
- Databases supported by NHibernate
However be aware that the level of support for the different database engines may vary, so make sure you research any known issues NHibernate may have with the specific database you are going to use.
NHiberate will help you out with the multi db part of your problem. The real challenge is the editing of tables.
I have done something similar to what you want with NHibernate, but the functionality is tricky to implement and difficult to get right.
Because NHibernate is an ORM you first need a class to load the data into so you will need to emit a class first. Then you need to generate a mapping file to map the db columns to the emitted classes properties. You can then uses the generated mapping file and all the other mapping files that your application needs to create the Configuration
. Finally you can use the schema export functionality of NH to generate the new table.
As I said tricky and not easy, bit possible.
精彩评论