"There was an error parsing the query" while inserting User
I've started learning NHibernate. I have the latest version installed and trying to run a very simple application. There's a class User
:
public class User
{
public virtual Guid Id { get; set; }
public virtual String Name { get; set; }
public virtual int Age { get; set; }
public override string ToString()
{
return string.Format("User{name='{0}', age={1}}", Name, Age);
}
}
Its mapping is:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="cs_nhibernate_test1"
namespace="cs_nhibernate_test1">
<class name="User">
<id name="Id">
<generator class="guid" />
</id>
<property name="Name" />
<property name="Age" />
</class>
</hibernate-mapping>
Then, my test program is like this:
class Program
{
static void Main(string[] args)
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof (User).Assembly);
new SchemaExport(cfg).Execute(false, true, true);
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
using (ISession session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
User user = new User { Name = "John Smith", Age = 25 };
session.Save(user);
transaction.Commit();
}
}
}
}
And hibernate.cfg.xml is like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="connection.connection_string">Data Source=FirstSample.sdf</p开发者_开发技巧roperty>
<property name="show_sql">true</property>
</session-factory>
The project is .NET 4.0 project, all the required files seem to be in output folder.
The error I get is:
NHibernate: INSERT INTO User (Name, Age, Id) VALUES (@p0, @p1, @p2);@p0 = 'John Smith' [Type: String (0)], @p1 = 25 [Type: Int32 (0)], @p2 = 4b0d4bbf- 7d3c-4bff-908d-ecddfdd8a5cd [Type: Guid (0)]
Unhandled Exception: System.Data.SqlServerCe.SqlCeException: There was an error parsing the query. [ Token line number = 1,Token line offset = 13,Toke n in error = User ]
Any ideas about fixing it?
Isn't user
a reserved keyword? http://msdn.microsoft.com/en-us/library/aa238507(v=sql.80).aspx
精彩评论