Posts Tagged ‘c#’

Hello all,

Want to make your life developing with nhibernate easier? Then, especially if you’re just getting started, you might want to have some IntelliSense support to ease the creation/modification of the .hbm.xml mapping files.

It’s quite simple:

1. Find the XML schema directory of your VS2010 Express (Beta 2, at this time) installation
Tools->Options will point you to the right place. Do not forget to select the Show all settings checkbox at the left bottom of the window:


2. Then, go to the folder you extracted the nhibernate binaries into. Go into the subfolder Required_Bins and copy the two .xsd files nhibernate-configuration.xsd and nhibernate-mapping.xsd


3. Copy them into the XMLSchemas folder you found in step 1

That’s all there is to it!

Without restarting VS2010 Express, the IDE’s IntelliSense will support you from now on with the mapping file’s tags and attributes (show available tags/attributes, help w/ code completion etc.)

Especially in the beginning of your O/R mapping career this will save you a great deal of time and nerves.

Enjoy and check back soon, for there is more to come!


Read Full Post »


This is my first post here, and I’d like to go right into medias res. The motivation is clear: I am a developer dealing with MS VS & nhibernate in order to map DB schemas. It is not a long time, since I am working on the topic, so I encountered a few troubles that can be shared, I guess. I carried the tests out using a sample schema on an Oracle 10g XE instance that I set up for this purpose.

Recently, I came across the problem that I needed to sort data upon retrieval. Nothing special there, one could say. But what I needed was sorting by:

a.) a custom field, provided by the user
b.) a custom order direction (asc/desc), also user provided

Unless I wanted to use the custom sort direction, HQL did the trick for me. I simply could create a query like:

Sample hql query using custom sort field

Just had to pass the customField parameter before calling the AllHouses query. However, when I try to pass also the sort direction, like in the following figure, any calls to the query fail.

Sample hql query using custom sort field and custom sort direction

At this point, any call to the query fails. The Oracle XE is obviously not able to assign the ASC/DESC sorting direction through a parameter. Hence, I came up w/ the following solution: Criteria queries! This way you can add custom order fields AND custom order directions.

In short words, it is simply done by using the AddOrder method of an ISession object. It takes as a parameter the field (custom provided by you), and has got two methods (Asc() and Desc()) for creating an Order object. The rest should be self-explanatory.

Here is how it works:

Criteria query using custom field and sort order

Simple, isn’t it? One more advantage is, that this way you are a bit more independent from DB-vendor-specific sorting possibilities. nhibernate will take care of creating the correct SQL syntax, no matter what the underlying DB is (as long as it’s supported, of course).

The nhibernate version I used for these tests is 1.2.

Stay tuned to the next time!


Read Full Post »