RJP Software Blog

.Net info and code snippets

WCF Self Hosted Named Pipe Endpoint

without comments

From time to time I find the need to knock up a self hosted WCF service with a named pipe endpoint. I will shortly put up some smaple code, but until then, her is an article that does a pretty good job of explaining what to do. WCF Console App With Named Pipe Endpoint

Read More

Written by Rich

May 15th, 2012 at 3:55 pm

Posted in WCF

NHibernate – Using the second level cache

without comments

Setting up the 2nd level cache in NHibernate is fairly straight forward. Take a look at this link for some easy to follow instructions: Quickly Setting Up And Using NHibernate’s Second Level Cache Also check this out: Using SysCache as secondary cache in NHibernate Its not for every query but can provide a significant performance [...]

Read More

Written by Rich

May 2nd, 2012 at 3:55 pm

Posted in NHibernate

NHibernate – Readonly / ETL type Processes

without comments

Most of NHibernate’s value is in its ability to manage a domain model and seamlessly send changes to the database. However, it can be used for Readonly and ETL scenarios (caveat: there may be better alternatives for these use cases). If you decide you would like to use NH in this way then I recommend [...]

Read More

Written by Rich

March 6th, 2012 at 4:27 pm

Posted in NHibernate

NHibernate – Calling Stored Procs

without comments

Although not something you normally want to do with an ORM layer such as NH, it is possible to call a stored proc. To do this use the following code: Session.GetNamedQuery(“usp_MySproc”) .SetParameter(“Param1″, myvariable1) .SetParameter(“Param2″, myVariable2) .SetResultTransformer( Transformers.AliasToBean(typeof(MyDowmainObject))) .List();

Read More

Written by Rich

February 27th, 2012 at 2:26 pm

Posted in NHibernate

SQL Script – Dropping Foreign Keys

without comments

I stumbled across the following script today which generates the SQL for dropping foreign keys: SELECT ‘ALTER TABLE ‘ + OBJECT_NAME(parent_object_id) + ‘ DROP CONSTRAINT ‘ + name FROM sys.foreign_keys WHERE referenced_object_id in (object_id(‘TableName1′), object_id(‘TableName2′), object_id(‘TableName3′))

Read More

Written by Rich

February 15th, 2012 at 3:41 pm

Posted in SQL Server

Nhibernate – List, Set or Bag for collection mappings?

without comments

I found a useful snippet on StackOverflow that clears this up… So, to quote: NHibernate semantics: List: Ordered collection of entities, duplicate allowed. Use a .net IList in code. The index column will need to be mapped in NHibernate. Set: Unordered collection of unique entities, duplicates not allowed. Use Iesi.Collection.ISet in code. It is important [...]

Read More

Written by Rich

February 15th, 2012 at 11:02 am

Posted in NHibernate

NHibernate 3.2 and SqlCE

without comments

I had some great fun configuring Nhibernate 3.2 with a Sql CE database today. As ever its easy when you know how! After an hour so so reading various blogs and dealing with some non illuminating NH error messages, I came up with a configuration that worked. So if you want to use NH with [...]

Read More

Written by Rich

February 14th, 2012 at 1:02 pm

Posted in NHibernate

NHibernate 3.2 “Mapping By Code” Snippets

without comments

As I trawl through the vairous blogs piecing things together, I thought that I would put together a page with some code snippets for the new NH 3.2 mapping API. Class Mappings Mapping a basic entity public class Person { public virtual int PersonId { get; set; } public virtual string LastName { get; set; [...]

Read More

Written by Rich

February 10th, 2012 at 4:45 pm

Posted in NHibernate

Reading and Listing Embedded Files

without comments

When writing unit tests I occasionally find the need to include embedded resources (mostly files – e.g. XML). This enables the tests to run anywhere without relying on a specific file structure. Each time I do this I seem to have to re-create the same test utility for managing these files so I thought I’d [...]

Read More

Written by Rich

February 8th, 2012 at 5:19 pm

Posted in Unit Testing

NHibernate – Set the Inverse on One To Many Relationships

without comments

Ayende has written an interesting blog on this here: Ayendes NHProf blog The salient point here is: Make sure that you specify inverse=’true’ on the <one-to-many> collection association otherwise NH will issue 2 SQL statements for a single Update/Insert.

Read More

Written by Rich

February 8th, 2012 at 4:50 pm

Posted in NHibernate