{"id":121,"date":"2007-10-15T08:36:07","date_gmt":"2007-10-15T14:36:07","guid":{"rendered":"http:\/\/jameskovacs.com\/2007\/10\/15\/ReSharper+Templates+For+NHibernate+And+Castle+ActiveRecord"},"modified":"2007-10-15T08:36:07","modified_gmt":"2007-10-15T14:36:07","slug":"resharper-templates-for-nhibernate-and-castle-activerecord","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2007\/10\/15\/resharper-templates-for-nhibernate-and-castle-activerecord\/","title":{"rendered":"ReSharper Templates for NHibernate and Castle ActiveRecord"},"content":{"rendered":"<p>I created a few simple ReSharper templates to make working with NHibernate and Castle ActiveRecord easier. They currently default to SQL Server 2005 because that&#8217;s what I do most of my work against. Feel free to customize to your heart&#8217;s content.<\/p>\n<p>You can grab them from <a href=\"http:\/\/jameskovacs.com\/downloads\/ReSharperOrmTemplates.zip\">here<\/a>. Simply import the templates&nbsp;into ReSharper via ReSharper&#8230; Options&#8230; Templates&#8230; Live (or File) Templates&#8230; User Templates&#8230; Import Templates from File&#8230; You&#8217;ll want to add the file templates to your Quick access list.<\/p>\n<p>The first file template is hibernate.cfg.xml. (N.B. ReSharper will try to name it hibernate.cfg1 and add the xml extension. Delete the &#8220;1&#8221; and hit enter.) The template will prompt you for the database server, database name, and mapping assembly.<\/p>\n<div style=\"font-size: 11pt; background: white; color: black; font-family: consolas, lucida console, monospace\">\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;?<\/span><span style=\"color: #a31515\">xml<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">version<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">1.0<\/span>\"<span style=\"color: blue\"> <\/span><span style=\"color: red\">encoding<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">utf-8<\/span>\"<span style=\"color: blue\"> ?&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;<\/span><span style=\"color: #a31515\">hibernate-configuration<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">xmlns<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">urn:nhibernate-configuration-2.2<\/span>\"<span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;<\/span><span style=\"color: #a31515\">session-factory<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.provider<\/span>\"<span style=\"color: blue\">&gt;<\/span>NHibernate.Connection.DriverConnectionProvider<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.driver_class<\/span>\"<span style=\"color: blue\">&gt;<\/span>NHibernate.Driver.SqlClientDriver<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.connection_string<\/span>\"<span style=\"color: blue\">&gt;<\/span>Data Source=localhost;Initial Catalog=DATABASE;Integrated Security=True<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.dialect<\/span>\"<span style=\"color: blue\">&gt;<\/span>NHibernate.Dialect.MsSql2005Dialect<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.use_outer_join<\/span>\"<span style=\"color: blue\">&gt;<\/span>true<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.show_sql<\/span>\"<span style=\"color: blue\">&gt;<\/span>false<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.query.substitutions<\/span>\"<span style=\"color: blue\">&gt;<\/span>true 1, false 0, yes 'Y', no 'N'<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">property<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">mapping<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">assembly<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">SimpleConfiguration<\/span>\"<span style=\"color: blue\">\/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;\/<\/span><span style=\"color: #a31515\">session-factory<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">hibernate-configuration<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<\/div>\n<p>The second file template is &lt;Class&gt;.hbm.xml. You will want to rename it &lt;Class&gt;.hbm as ReSharper will add the xml extension for you. The template will prompt you for the class name and primary key name. You&#8217;ll also want to modify the PK generator. You&#8217;ll note that default-access is &#8220;field.pascalcase-m-underscore&#8221;, which means that if you map a property called &#8220;Name&#8221;, NHibernate will access it by the corresponding field name, &#8220;m_Name&#8221;. Change your default-access to whichever naming convention you prefer. (See <a href=\"http:\/\/www.hibernate.org\/hib_docs\/nhibernate\/1.2\/reference\/en\/html\/mapping.html#mapping-declaration-property\">property access and naming strategies<\/a> in the NHibernate documentation.)<\/p>\n<div style=\"font-size: 11pt; background: white; color: black; font-family: consolas, lucida console, monospace\">\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;?<\/span><span style=\"color: #a31515\">xml<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">version<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">1.0<\/span>\"<span style=\"color: blue\"> <\/span><span style=\"color: red\">encoding<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">utf-8<\/span>\"<span style=\"color: blue\"> ?&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;<\/span><span style=\"color: #a31515\">hibernate-mapping<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">xmlns<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">urn:nhibernate-mapping-2.2<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">namespace<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">SimpleConfiguration<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">assembly<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">SimpleConfiguration<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">default-access<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">field.pascalcase-m-underscore<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">default-lazy<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">false<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">default-cascade<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">none<\/span>\"<span style=\"color: blue\"> &gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;<\/span><span style=\"color: #a31515\">class<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">CLASS<\/span>\"<span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">id<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">PRIMARYKEY<\/span>\"<span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">generator<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">class<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">assigned<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;\/<\/span><span style=\"color: #a31515\">id<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;\/<\/span><span style=\"color: #a31515\">class<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">hibernate-mapping<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<\/div>\n<p>Lastly we have the Live template for Castle ActiveRecord configuration. You can insert this into app.config or web.config. Simple position your cursor inside &lt;configuration&gt; and type arconfig&lt;TAB&gt;. If you already have other configuration sections, you&#8217;ll have to merge the activerecord section with the others.<\/p>\n<div style=\"font-size: 11pt; background: white; color: black; font-family: consolas, lucida console, monospace\">\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;<\/span><span style=\"color: #a31515\">configSections<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">section<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">name<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">activerecord<\/span>\"<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">type<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">configSections<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\">&nbsp;<\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;<\/span><span style=\"color: #a31515\">activerecord<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;<\/span><span style=\"color: #a31515\">config<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">add<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">key<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.driver_class<\/span>\"<span style=\"color: blue\"> <\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">value<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">NHibernate.Driver.SqlClientDriver<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">add<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">key<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.dialect<\/span>\"<span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">value<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">NHibernate.Dialect.MsSql2005Dialect<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">add<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">key<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.provider<\/span>\"<span style=\"color: blue\">&nbsp; &nbsp;  <\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">value<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">NHibernate.Connection.DriverConnectionProvider<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &lt;<\/span><span style=\"color: #a31515\">add<\/span><span style=\"color: blue\"> <\/span><span style=\"color: red\">key<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">hibernate.connection.connection_string<\/span>\"<span style=\"color: blue\"> <\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &nbsp; &nbsp; &nbsp;  <\/span><span style=\"color: red\">value<\/span><span style=\"color: blue\">=<\/span>\"<span style=\"color: blue\">Data Source=DBSERVER;Initial Catalog=DATABASE;Integrated Security=SSPI<\/span>\"<span style=\"color: blue\"> \/&gt;<\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&nbsp; &lt;\/<\/span><span style=\"color: #a31515\">config<\/span><span style=\"color: blue\">&gt;&nbsp; &nbsp; &nbsp; <\/span><\/pre>\n<pre style=\"margin: 0px\"><span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">activerecord<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<\/div>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I created a few simple ReSharper templates to make working with NHibernate and Castle ActiveRecord easier. They currently default to SQL Server 2005 because that&#8217;s what I do most of my work against. Feel free to customize to your heart&#8217;s content. You can grab them from here. Simply import the templates&nbsp;into ReSharper via ReSharper&#8230; Options&#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-dotnetgeneral","category-dotnettools"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}