Hello,
I have a project that is supposed to run on different (at least 2) databse backends, so users can choose (currently between MSSQL and SQLite). I've just started learning NHibernate, following the tutorial on NHForge.
Now, my current Architecture looks like this:
MyProject.DAL
Contains NewsItem and INewsItemRepository. NewsItem is a POCO, essentially just an int Id and string Title.
INewsItemRepository is the Interface that includes CRUD Functionality.
MyProject.Plugins.DAL.MSSQL
This class implements the backend. It includes hibernate.cfg.xml, NewsItem.hbm.xml and NewsItemRepository.
The cfg holds the Driver and ConnectionString, the hbm is the SQL-Server specific Mapping, and NewsItemRepository implements the INewsItemRepository.
If I want to add the MyProject.Plugins.DAL.SQLite, I will have to duplicate all this, which is logical. However, I wonder if that is the correct approach? I feel like I'm unnecessarily duplicating things. I mean: I need to make sure the mapping is Database-specific, and that I update all my Plugins if the database changes. But this architecture still seems somehow... bloated.
Am I doing the right thing here? Or are there common patterns about what goes into the general business assembly and what needs to be kept separate for each database?
Edit: One of the challenges here is the handling of sql-types. For example, strings are mapped as nvarchar(255) by default, and if I need ntext in MSSQL, i'll have to use the <column sql-type="NTEXT" syntax, do I? I guess that specifying sql-type is database-dependent, so I'll need my mapping separated per database? Or is there a built-in mechanism to have mappings "inherit" each other? (I.e. have one .hbm.xml with all the <property> Tags in the general DAL Project and then .hbm's in each Backend-Assembly containing the columns?