SqlCeException NHibernate
I'm using Sql Compact Edition.
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 to 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" ?>
<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" 开发者_StackOverflow/>
    <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 ]
What could be this???
you dont specify the table so nhibernate takes Set as the tablename. Set is a reserved word in most datasbases. You can try to escape it
<class name="Set" table="`Set`">
i'm not sure if i used the correct backticks though
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论