Querying Over Multiple Child Collections With NHibernate

Typically with NHibernate, I’m always querying over one table and eager fetching it’s child collections. I’m also only performing WHERE conditions on that initial table I am querying over.

The other day though, I needed to solve a problem where I was adding WHERE conditions to the child collections. Now in SQL, this is quite easy but in NHibernate, it took me a while to figure out how to do this efficiently.

Continue reading

Mask a Phone Number Field but Only Save the Numbers using jQuery

Masking a phone number field is relatively easy by utilizing one of the many jQuery masking plug-ins. It will turn your input field from this: 5554449999 into this: (555) 444-9999 which looks much nicer but at the same time that becomes the text that will be sent when you post back the form to the server.

Continue reading

Restrict Access to an MVC Action or Controller by IP Address using a Custom Action Filter

Scenario: You want to lock down access to a particular action or entire controller in your MVC application via the users IP address.  This can be particularly useful if you would like to restrict the Admin portion of your website to just your company’s IP address range.

There are several ways to accomplish this task. IIS allows you to restrict by IP Address but what if you want to do it programmatically…

Continue reading

Explicitly Specifying the Identity Column Value using Fluent NHibernate

I recently ran into a situation where I was saving to a database table that did not have an auto-incrementing identity column. I didn’t realize that at the time when I was setting up my NHibernate mapping and it caused me a headache for about half an hour attempting to figure out what was causing the problem.

Continue reading

Need to dump an object? Serialize it into XML.

I recently found myself wanting to dump an object into a human readable text format for debugging purposes. I first looked into Microsoft’s ObjectDumper class included in the samples folder of Visual Studio 2008.

It works okay but by default it outputs to the console and isn’t formatted very well. I spent about half an hour modifying it to my liking but I still couldn’t get it looking right and just wanted something easier to work with.

Continue reading