Thursday, 28 January 2010

NHibernate.HibernateException: Incorrect syntax for definition of the 'TABLE' constraint.

While using Spring.NET and NHibernate on a ASP.NET web application I came across the following error:

System.Data.SqlClient.SqlException: Incorrect syntax for definition of the 'TABLE' constraint.
NHibernate.HibernateException: Incorrect syntax for definition of the 'TABLE' constraint.

The problem was that I was trying to name a column in a SQL Server database as "References", which must be a protected name because it didn't like it. When I changed my code to call the column "Refs" instead the problem went away.

[Property(Name = "Refs", Column = "References", Length = 4001)]
//Length 4001 is equivalent to nvarchar(MAX)
public virtual string Refs { get; protected internal set; }

3 comments: