Syntax to define a NHibernate Filter with Fluent Nhibernate?

If you build Fluent from source, there is now support for filters. You use them like this: First create a class inheriting from FluentNHibernate.Mapping.FilterDefinition: using FluentNHibernate.Mapping; namespace PonyApp.FluentFilters { public class PonyConditionFilter : FilterDefinition { public PonyConditionFilter() { WithName(“PonyConditionFilter”) .AddParameter(“condition”,NHibernate.NHibernateUtil.String); } } } In your ClassMap for your class, use the ApplyFilter method: namespace PonyApp.Entities.Mappings … Read more

How do add NOLOCK with nHibernate?

SetLockMode(LockMode.None) or connection.isolation ReadUncomitted does NOT append a NOLOCK to your queries. Ayende goes into the correct answer on his blog: If you’re using <sql-query> you can do the following: <sql-query name=”PeopleByName”> <return alias=”person” class=”Person”/> SELECT {person.*} FROM People {person} WITH(nolock) WHERE {person}.Name LIKE :name </sql-query> Note the WTIH(nolock) appended to the FROM clause.

DateTime precision in NHibernate and support for DateTime2 in NHibernate SchemeExport

Actually the NHibernate reference states that the DateTime nhibernate type will store the .NET DateTime as an SQL datetime truncated at the second level (no millisecond granularity) As such it provides the Timestamp NHibernate type (type=”Timestamp” in the mapping) which will store a .NET DateTime as an SQL datetime without truncation. Note here that an … Read more

Generate XML mappings from fluent Nhibernate

You can do something like: config.Mappings(m => { m.FluentMappings.ExportTo(“…file path here…”); m.HbmMappings.ExportTo(“…file path here…”); m.AutoMappings.ExportTo(“…file path here…”); { ); I don’t like it myself. If I find some better way (if such exists at all) I’ll update the answer. See http://blog.jagregory.com/2009/02/03/fluent-nhibernate-configuring-your-application/ Or if broken, see this instead https://github.com/jagregory/fluent-nhibernate/wiki/Database-configuration

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