WCF Self Hosted Named Pipe Endpoint
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 MoreNHibernate – Using the second level cache
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 MoreNHibernate – Readonly / ETL type Processes
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 MoreNHibernate – Calling Stored Procs
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 MoreSQL Script – Dropping Foreign Keys
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 MoreNhibernate – List, Set or Bag for collection mappings?
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 MoreNHibernate 3.2 and SqlCE
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 MoreNHibernate 3.2 “Mapping By Code” Snippets
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 MoreReading and Listing Embedded Files
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 MoreNHibernate – Set the Inverse on One To Many Relationships
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