Difference between Get and Load

The reference provided by Brian explains it quite clearly. However, the main difference is that Load doesn’t hit the database to check and load the entity you require, since it assumes you know the entity exists. The object returned by Load is some kind of proxy that lazily fetches the real data when required or … Read more

Best way to delete all rows in a table using NHibernate?

In the TearDown of my UnitTests, I mostly do this: using( ISession s = … ) { s.Delete (“from Object o”); s.Flush(); } This should delete all entities. If you want to delete all instances of one specific entity, you can do this: using( ISession s = …. ) { s.Delete (“from MyEntityName e”); s.Flush(); … Read more

The length of the string value exceeds the length configured in the mapping/parameter

This is a well known issue with NHibernate handling nvarchar(max), see : http://geekswithblogs.net/lszk/archive/2011/07/11/nhibernatemapping-a-string-field-as-nvarcharmax-in-sql-server-using.aspx For some years now, I have been file mapping nvarchar(max) columns to StringClob without encountering any problem : <property name=”myProp” column=”MY_PROP” not-null=”true” type=”StringClob” access=”property”></property> This link (from the comments) describes the fluent mapping required to fix this issue: https://www.tritac.com/nl/blog/fluent-nhibernate-nvarchar-max-fields-truncated-to-4000-characters/ Map(x => x.Description).CustomType(“StringClob”).CustomSqlType(“nvarchar(max)”);

How do I view the SQL that is generated by nHibernate?

You can put something like this in your app.config/web.config file : in the configSections node : <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler,log4net”/> in the configuration node : <log4net> <appender name=”NHibernateFileLog” type=”log4net.Appender.FileAppender”> <file value=”logs/nhibernate.txt” /> <appendToFile value=”false” /> <layout type=”log4net.Layout.PatternLayout”> <conversionPattern value=”%d{HH:mm:ss.fff} [%t] %-5p %c – %m%n” /> </layout> </appender> <logger name=”NHibernate.SQL” additivity=”false”> <level value=”DEBUG”/> <appender-ref ref=”NHibernateFileLog”/> </logger> </log4net> … Read more

Fluent NHibernate: How to create one-to-many bidirectional mapping?

To get a bidirectional association with a not-null foreign key column in the Details table you can add the suggested Owner property, a References(…).CanNotBeNull() mapping in the DetailsMap class, and make the Summary end inverse. To avoid having two different foreign key columns for the two association directions, you can either specify the column names … Read more

Using MiniProfiler’s database profiling with NHibernate

[UPDATE] Please see the following links for a version of that uses RealProxy to proxy the SqlCommand – batching is now supported blog http://blog.fearofaflatplanet.me.uk/mvcminiprofiler-and-nhibernate-take-2 gist https://gist.github.com/1110153 I’ve left the original answer unaltered as it was accepted. [/UPDATE] I’ve managed to partially get this to work by implementing a Profiled Client Driver (example for Sql Server … Read more

queryover and (x like ‘a’ or y like ‘a’)

You could use the NHibernate Disjunction class to do this in a more elegant (IMHO) fashion: var disjunction= new Disjunction(); disjunction.Add(Restrictions.On<Type>(e => e.Code).IsLike(codePart)); disjunction.Add(Restrictions.On<Type>(e => e.Description).IsLike(codePart)); //(and so on) and then: query.Where(disjunction) Each “OR” is a separate instruction, which helps if you want to add the predicates conditionally.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)