I'm having some issues with a query of a table that includes a space in it's name
If i write a sql-query it works fine, ie SELECT * FROM [product groups], but when using NHibernate CreateQuery everything breaks
using (ISession session = SessionFactory.OpenSession())
{
IQuery query = session.CreateQuery("FROM [product groups]");
IList<ProductGroups> results = query.List<ProductGroups>();
}
Will generate the error
Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 5 at
NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() at NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse()
...
If I use a CreateSQLQuery it works
ISQLQuery query = session.CreateSQLQuery("SELECT ID, Title, [Available as develop] FROM [product groups]").AddEntity(typeof(ProductGroups));
IList<ProductGroups> results = query.List<ProductGroups>();
The mapping file looks like this
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="ListModels.ProductGroups, ListModels" lazy="true" table="Product groups">
<id name="ID">
<generator class="native" />
</id>
<property name="Title" />
<property name="AvailableAsDevelopmentLicense" column="Available as develop" />
</class>
</hibernate-mapping>
Why would not CreateQuery work?