(Update: Added the code to initialize Castle Windsor as well)
I've known about LINQPad for a long time but for some reason the usefulness of it just hit me yesterday. In a moment of clarity I plopped my money down for all the bells and whistles and started playing. I watched the video on the LINQPad site (you should too) and began thinking of the different ways it would most benefit my project. Of course the first step would be getting LINQPad to use the my actual code.
My current project is built on S#arp Architecture with a few modifications. One of those modifications is the implementation of NHibernate.Linq in the repositories. Using LINQPad to write snippets and query your database is cool but using it to query your NHibernate repositories is other-side-of-the-pillow (or Billy D. Williams) cool. It's also very easy to set up.
I'm using the Northwind example that is included with S#harp Architecture with the addition of NHibernate.Linq to the SupplierRepository. With LINQPad open hit F4 to open the Advanced Query Properties window and add the following additional references:
These are for a basic setup, you might need to add additional references for your project.
Next add these Additional Namespace Imports
Now all that's left is to snag some code from the Global.ascx file to configure log4net, initialize NHibernate, Castle Windsor and adjust the paths to the web.config, NHibernate.config and the assembly that contains your mapped entities. Also note the change from WebSessionStorage to SimpleSessionStorage.
var Log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
Log.Info( "Application Start" );
IWindsorContainer container = new WindsorContainer();
ComponentRegistrar.AddComponentsTo( container );
ServiceLocator.SetLocatorProvider( () => new WindsorServiceLocator( container ) );
var repo = ( ISupplierRepository )ServiceLocator.Current.GetService( typeof( ISupplierRepository ) );
var supplier = from s in repo
Now you can use LINQPad to quickly try new code utilizing your custom assemblies.
12-17-2009 4:05 PM