Hibernate is a large scale project which covers 95 percent of common data persistence related programming tasks about SQL and database. We can call hibernate as one upper level of database(OULOD). I am kidding, we don't need any more terminologic and cryptic acronyms for making our documents hard to read as hell.
NHibernate is the port of Hibernate to .NET world. I don't know what developers think about ORMs after LINQ which makes these kind of things very very easy and neat. Well this article will introduce you to nice and dandy nhibernate and implements .NET membership, role, and profile providers.
About a week ago, I saw this project. It did not have
ProfileProvider and I started digging and writing my implementation of
ProfileProvider. It did not tested under heavy load. Just a starting point.
You don't have to read it (because I don't believe reading documents takes you anywhere). But if you really wonder what this hibernate is, you can read it here.
As you can see, it's a pretty simple and basic nhibernate project. The main provider inherited classes are:
NHibernateMembershipProvider: handles the membership provider related tasks from abstracted level.
NHibernateProfileProvider: I implemented this from real sqlprovider decompiled classes. I have not tested every aspect of this class. Please do that and send me bugs.
NHibernateRoleProvider: Done the role provider implementation for .NET 2.0 class.
Using the Provider
Step 1: You need to make your database ready. I use mysql for this article and the code tested under mysql. Create a database named
Step 2: Run the script which comes with the zip file named
NHibernateProviderDataModel - mysql.ddl under NHibernateProviderDatabase\Create Scripts. I know this can be tricky. Even I get errors and swear the GUI tools. But it's fast and open source database and I like it.
Step 3: Open NHibernateProvider.sln with VS.NET 2008. and find web.config file and change the connection string at line:140 to point to your mysql server.
That is all. Now you have nhibernate which works on most famous databases (in theory). Click on the "Play" button.
I must say that it was already designed for me. I just added one more table to store profile data. We have 7 table names of those:
ApplicationUserRole: Connection table for user and roles. Holds just application id, user id and role id
ApplicationUser: Contains which user belongs to which application. Holds application id and user id
ApplicationRole: Contains which role belongs to which application. Holds application id and role id
MembershipUser: Holds initial user data
First, I was afraid for there was no connection between profiles and any other table. But then I thought that there are a lot of connections between other tables for more work. If I put any more connections between profile and any table, this means database has to check foreign keys when any delete or insert appears.
Points of Interest
If you develop any nhibernate project, don't forget to embed your mapping files into build. Otherwise you will read a lot of forum entry and solving this took longer then you would expect. Just select your mapping file "any.hbm.xml" and press F4 to open properties dialog and select "Embedded Resource" in "Build Action" line.
I have not used nhibernate in any of my projects. With this tool, I plan to support any database as much as I can. This article and code was a start. My next target is SQLite. Don't hesitate to join me. I am open to any suggestions/testing/debugging.