Click here to Skip to main content
Licence Ms-PL
First Posted 1 Apr 2009
Views 9,896
Downloads 276
Bookmarked 14 times

Nhibernate .NET Providers

By mascix | 2 Apr 2009
NHibernate based Profile, Membership, Role Providers written in C#
3 votes, 42.9%
1

2

3
2 votes, 28.6%
4
2 votes, 28.6%
5
3.40/5 - 7 votes
μ 3.40, σa 3.57 [?]

Introduction

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.

Background

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.

Class Diagram

As you can see, it's a pretty simple and basic nhibernate project. The main provider inherited classes are:

  1. NHibernateMembershipProvider: handles the membership provider related tasks from abstracted level.
  2. 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.
  3. NHibernateRoleProvider: Done the role provider implementation for .NET 2.0 class.

class diagram of the nhibernate providers

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 nhibernateprovidertest.

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. :)

Database Design

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:

  1. ApplicationUserRole: Connection table for user and roles. Holds just application id, user id and role id
  2. ApplicationUser: Contains which user belongs to which application. Holds application id and user id
  3. ApplicationRole: Contains which role belongs to which application. Holds application id and role id
  4. Role
  5. MembershipUser: Holds initial user data
  6. Application
  7. Profiles: columns:
    1. PropertyNames
    2. PropertyValuesString
    3. LastActivityDate
    4. PropertyValuesBinary

nhibernate providers

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.

History

  • 2009-04-01 First release

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

mascix

Software Developer (Senior)
http://www.mascix.com/
Turkey Turkey

Member
some of my projects:
sqlite asp.net profile membership role provider
play3w and for dom pro video player
english turkish dictionary

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 Pinmemberokdone23:05 22 Sep '11  
GeneralMy vote of 1 Pinmembertrevorde stickman11:24 1 Apr '09  
GeneralMy vote of 1 Pinmemberpita20099:42 1 Apr '09  
GeneralMy vote of 1 PinmemberPuchko Vasili7:55 1 Apr '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 2 Apr 2009
Article Copyright 2009 by mascix
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid