Learning NHibernate – Part 2

by trdunsworth

As I said in an earlier post, I’d decided to use NHibernate in a series of programs I’m writing because I preferred the stability and the  maturity of the code, especially since I have to use it against .NET 3.5 and an Oracle database. I know that Oracle updated ODP.NET to work with Entity Framework, but I’ve only seen it working on .NET 4 I’m concerned about using it since it just came out of beta earlier this year. Yeah, I know that this becomes a preference thing, but I get to make that call since I have to be comfortable with what I’m coding and how I’m doing it. If the database were SQLServer anything, I would switch to EF because it is written by Microsoft for Microsoft products (SQLServer, .NET, Visual Studio, etc.) but with the environment I have, I think I’m making the best choice.

The first part of setting it up seems pretty straight forward. I need classes which contain my tables so I can work with POCOs (I even understand what they are these days…) and I need some sort of mapping to link class to database. That way I can create the objects I need and ensure they are both type safe and useful when I need to do CRUD operations or if I need to create code which makes decisions on what it finds in the objects themselves. This is when I also am very thankful for NuGet, because I can

I’ve looked at several books, but they all leave me feeling dumber than when I started. I’ve run across a 6 part tutorial which seems to make it more understandable for me at least. The tutorial is at Geeks with Blogs and can be found here. I worked through the tutorial, all 6 parts, and really started getting it, so many thanks to Bob Palmer for this and for helping start me over the hump. Now I have some ideas of what to code and how to code it. The question then becomes what can I do with it to get the things I need to do done? The first challenge is going to be with the admin code and being able to adjust to the intersection tables and ensure that what we CRUD in the base tables gets persisted so we can get the updates in and out the best way possible. I think this is where a lot of my NHibernate coding is going to be useful. I just have to look at how to wire it all up to a form so I can pull back data to edit, or I can create a record whole cloth.

I think I’m going to need the advanced queries when I get into the actual logic of the program. That proggie has to read information from several tables to determine if this meets the send criteria or no. If so, then send it and delete it. If not, then it may need to persist it long enough to see if it will meet the send criteria for up to 30 minutes after creation. After that, forget it.

Advertisements