Token offset sql error NHIBERNATE
I have this table:
TABLE "Set": [PK:IdSet (int), IdProject (int),IdSetState(int),IdPriority(int),NumSet(int),Unit(nchar),NumDisc(int)]
And using NUnit testing.
this is my test method:
[Test]
public void Can_add_Set()
{
var set = new Set { IdProject = 2, IdSetState = 2, NumDisc = 1, IdPriority = 3, NumSet = 100};
setRepository.AddSet(set);
}
this is my method for insert a Set:
public void AddSet(Set set)
{
using (ISession session = NHibernateSessionBuilder.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(set);
transaction.Commit();
}
}
This is the mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernat开发者_如何转开发e-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="AdminProject"
namespace="AdminProject.Business.Entity">
<class name="Set">
<id name="IdSet">
<generator class="identity"/>
</id>
<property name="IdProject" />
<property name="IdSetState" />
<property name="IdPriority" />
<property name="Unit" />
<property name="NumDisc" />
<property name="NumSet" />
</class>
</hibernate-mapping>
when the session.save(set); occurs this error:
"User code not control SqlCeException"
"Failed to parse the query. [ Token line number = 1,Token line offset = 13,Token in error = Set ]"
How can fix this?
Isn't set a reserved keyword? Try qualifying it with "" or []
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="AdminProject"
namespace="AdminProject.Business.Entity">
<class name="[Set]">
<id name="IdSet">
<generator class="identity"/>
</id>
<property name="IdProject" />
<property name="IdSetState" />
<property name="IdPriority" />
<property name="Unit" />
<property name="NumDisc" />
<property name="NumSet" />
</class>
</hibernate-mapping>
SQL CE reserved keywords: http://msdn.microsoft.com/en-us/library/aa258313(v=sql.80).aspx
精彩评论