Unintended consequences - Transactions

What’s wrong with the following code? using (var transaction = session.BeginTransaction()) { session.Save(something); transaction .Commit(); } Nothing if you are using MySQL connector 6.0, which has the following Dispose method on its MySqlTransaction class. protected override void Dispose(bool disposing) { if ((((this.conn != null) && (this.conn.State == ConnectionState.Open)) || this.conn.SoftClosed) && this.open) { this.Rollback(); } base.Dispose(disposing); } But if you are using 5.0.9, check out this code (which is actually from the underlying DbTransaction object). »

NHibernate Connection Release Modes

Some team members and I spent the better part of a few hours today researching a really weird bug we were seeing with our data access code built on NHibernate. The basic symptoms were a duplicate key violation on a unique column in a table. This only happened under decent load, so reproducing in dev was pretty hard. To make matters more interested, it only happened with NHibernate 2.0. We started looking at MySQL logs and saw the following. »

Thoughts on #RichCC

A couple weekends ago, I attended Richmond Code Camp and had a great time. This was different than the last code camp I went to, in the fact that I spent most of the day presenting, not watching others. I have coded in front of co-workers before. I have given presentations to strangers before. But I had never coded in front of strangers before. There were a lot of things I learned. »

NHibernate CodeCamp Talk - Source Code

I have published the source of my Code Camp talk here. Check it out and post any questions. Thanks to everyone who showed up for the NHibernate talk. It went really well and everyone had tons of great questions. Feel free to post feedback here, both positive and negative, so the next time I give this talk, it will be even better. For those of you that just want a little more guidance on NHibernate, here are some good links: NH Forge NHibernate Documentation Fluent NHibernate S#arp Architecture NHibernate best practices Also, thanks to the coordinators of Richmond CC. »

Why you should use NHibernate.Linq, not Criteria or HQL

What’s wrong with the following? return s.CreateQuery("from CodeCamp c where c.Name = :name order by c.Name") .SetParameter("name", "test") .List<codecamp>(); return s.CreateCriteria<codecamp>() .Add(Expression.Eq("Name", "test")) .AddOrder(Order.Asc("Name")) .List<codecamp>(); There are string references to .NET properties. That is a no-no. If there is a typo, you get runtime errors and not compile time errors. Now, good tests would catch it, but if you want the absolute fastest way to catch typos, NHibernate.Linq is the way to go. »

Speaking at Richmond Code Camp on NHibernate

On October 3rd, I encourage anyone who wants to learn about NHibernate to come to Richmond Code Camp. I will be giving a 100 level talk describing how to get started using it, and what it really is. My initial idea is to create a fairly simple ASP.NET MVC application without persistence (use in memory Lists). And, in an hour, make it 100% persisted with transactions, lazy loading, etc. I am a little concerned it will be hard to teach NHibernate and get it done in an hour, but I am going to go for it. »

nvarchar vs. varchar in SQL Server, BEWARE

I discovered one of the scariest performance problems with SQL Server I have ever seen today. This problem is so easy to over look, yet extremely detrimental to database performance. Consider the following table. BEGIN TRANSACTION GO CREATE TABLE dbo.Users ( id int NOT NULL, username varchar(50) NOT NULL ) GO ALTER TABLE dbo.Users ADD CONSTRAINT PK_Users_id PRIMARY KEY CLUSTERED ( id ) GO CREATE UNIQUE NONCLUSTERED INDEX IX_Users_username ON dbo.Users ( username ) GO COMMIT Now look at the query plans of the following queries, that differ by a single character. »