<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Alan Northam : LINQPad</title><link>http://devlicio.us/blogs/alan_northam/archive/tags/LINQPad/default.aspx</link><description>Tags: LINQPad</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Using LINQPad with NHibernate and S#arp Architecture</title><link>http://devlicio.us/blogs/alan_northam/archive/2009/12/17/using-linqpad-with-nhibernate.aspx</link><pubDate>Thu, 17 Dec 2009 22:05:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:54611</guid><dc:creator>anortham</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;(Update: Added the code to initialize Castle Windsor as well)&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve known about LINQPad for a long time but for some reason the usefulness of it just hit me yesterday.&amp;nbsp; In a moment of clarity I plopped my money down for all the bells and whistles and started playing.&amp;nbsp; I watched the &lt;a href="http://www.linqpad.com/UsingLINQPad.mov" target="_blank"&gt;video&lt;/a&gt; on the LINQPad site (you should too) and began thinking of the different ways it would most benefit my project.&amp;nbsp; Of course the first step would be getting LINQPad to use the my actual code.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;My current project is built on &lt;a href="http://www.sharparchitecture.net/" target="_blank"&gt;S#arp Architecture&lt;/a&gt; with a few modifications.&amp;nbsp; One of those modifications is the implementation of NHibernate.Linq in the repositories.&amp;nbsp; 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.&amp;nbsp; It&amp;#39;s also very easy to set up.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using the Northwind example that is included with S#harp Architecture with the addition of NHibernate.Linq to the SupplierRepository.&amp;nbsp; With LINQPad open hit F4 to open the Advanced Query Properties window and add the following additional references:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;NHibernate.dll&lt;/li&gt;
&lt;li&gt;NHibernate.Linq.dll&lt;/li&gt;
&lt;li&gt;SharpArch.Core.dll&lt;/li&gt;
&lt;li&gt;SharpArch.Data.dll&lt;/li&gt;
&lt;li&gt;SharpArch.Web.Castle.dll&lt;/li&gt;
&lt;li&gt;SharpArch.Web.dll&lt;/li&gt;
&lt;li&gt;SharpArch.Testing.dll&lt;/li&gt;
&lt;li&gt;FluentNHibernate.dll&lt;/li&gt;
&lt;li&gt;log4net.dll&lt;/li&gt;
&lt;li&gt;Northwind.Core.dll&lt;/li&gt;
&lt;li&gt;Northwind.Data.dll&lt;/li&gt;
&lt;li&gt;Northwind.Web.dll&lt;/li&gt;
&lt;li&gt;Northwind.ApplicationServices.dll&lt;/li&gt;
&lt;li&gt;Castle.Core.dll&lt;/li&gt;
&lt;li&gt;Castle.Windsor.dll&lt;/li&gt;
&lt;li&gt;CommonServiceLocator.WindsorAdapter.dll&lt;/li&gt;
&lt;li&gt;Microsoft.Practices.ServiceLocation.dll&lt;/li&gt;
&lt;li&gt;Castle.MicroKernel.dll&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are for a basic setup, you might need to add additional references for your project.&lt;/p&gt;
&lt;p&gt;Next add these Additional Namespace Imports&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;NHibernate.Cfg&lt;/li&gt;
&lt;li&gt;NHibernate.Linq&lt;/li&gt;
&lt;li&gt;SharpArch.Testing.NHibernate&lt;/li&gt;
&lt;li&gt;SharpArch.Data.NHibernate&lt;/li&gt;
&lt;li&gt;log4net&lt;/li&gt;
&lt;li&gt;log4net.Config&lt;/li&gt;
&lt;li&gt;Northwind.Data&lt;/li&gt;
&lt;li&gt;Northwind.Data.NHibernateMaps&lt;/li&gt;
&lt;li&gt;Castle.Windsor&lt;/li&gt;
&lt;li&gt;Microsoft.Practices.ServiceLocation&lt;/li&gt;
&lt;li&gt;CommonServiceLocator.WindsorAdapter&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now all that&amp;#39;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.&amp;nbsp; Also note the change from WebSessionStorage to SimpleSessionStorage.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/alan_5F00_northam/queryWindowNew.jpg"&gt;&lt;img width="800" border="0" src="http://devlicio.us/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/alan_5F00_northam/queryWindowNew.jpg" style="border:0;" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/alan_5F00_northam/queryWindow.jpg"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;pre class="c#" name="code"&gt;var Log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
XmlConfigurator.Configure(new FileInfo(@&amp;quot;C:\src\Sharp-Architecture\src\NorthwindSample\app\Northwind.Web\Web.config&amp;quot;));
Log.Info( &amp;quot;Application Start&amp;quot; );
	
IWindsorContainer container = new WindsorContainer();
ComponentRegistrar.AddComponentsTo( container );
ServiceLocator.SetLocatorProvider( () =&amp;gt; new WindsorServiceLocator( container ) );

NHibernateSession.Init(
	new SimpleSessionStorage(),
	new[] {@&amp;quot;C:\src\Sharp-Architecture\src\NorthwindSample\app\Northwind.Web\bin\Northwind.Data.dll&amp;quot;},
	new AutoPersistenceModelGenerator().Generate(),
	@&amp;quot;C:\src\Sharp-Architecture\src\NorthwindSample\app\Northwind.Web\NHibernate.config&amp;quot; );
	
var repo = ( ISupplierRepository )ServiceLocator.Current.GetService( typeof( ISupplierRepository ) );

var supplier = from s in repo
				where s.CompanyName.StartsWith(&amp;quot;Bigfoot&amp;quot;)
				select s;
				
supplier.Dump();

&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you can use LINQPad to quickly try new code utilizing your custom assemblies.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=54611" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/alan_northam/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/alan_northam/archive/tags/Sharp+Architecture/default.aspx">Sharp Architecture</category><category domain="http://devlicio.us/blogs/alan_northam/archive/tags/LINQPad/default.aspx">LINQPad</category></item></channel></rss>