NHibernate configuration for uni-directional one-to-many relation

NH3 and above allow to correct save entities in case of uni-directional one-to-many mapping without annoying save null–save–update cycle, if you set both not-null=”true” on <key> and inverse=”false” on <one-to-many> FluentNHibernate code snippet for that: public class MasterMap : ClassMap<Master> { public MasterMap() { Id(x => x.MasterId); Map(x => x.Name); HasMany(x => x.Details) .Not.Inverse() //these … Read more

Binary Blob truncated to 8000 bytes – SQL Server 2008 / varbinary(max)

I too have encountered a similar problem and after much experimentation I noticed that when using Nhibernate to generate my schema to a file the generated column type was always length 8000. Setting setting CustomSqlType to Varbinary(max) as suggested above made no difference, however, this work around in my FluentMapping seemed to do the trick: … Read more

IndexOutOfRangeException Deep in the bowels of NHibernate

Yes its a common problem, you are using the Column “EndDate” twice in your mapping definition (for both Company and PrimaryListing) and that is not allowed. One of them has to go, or have an additional EndDate column (one for each association) check this too nHibernate 2.0 – mapping a composite-id *and* many-to-one relationship causes … Read more

nHibernate mapping to custom types

You need to implement your own IUserType. See this blog post for details. I’ll also paste the relevant section below in case the blog disappears. In NHibernate, a custom mapping type is a class that derives from either the IUserType or ICompositeUserType interfaces. These interfaces contain several methods that must be implemented, but for our … Read more

List vs Set vs Bag in NHibernate

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 (NH prior to v4) or System.Collections.Generic.ISet (NH v4+). It is important to override GetHashCode and Equals to … Read more