嗨,我创建名为 baza.sdf 的空本地数据库
我的域名
namespace mapowanie.Domain {
public class User
{
public virtual Guid Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
} }
我的映射 hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="mapowanie"
namespace="mapowanie.Domain">
<class name="User">
<id name="Id" generator="guid" />
<property name="FirstName" type="string" />
<property name="LastName" type="string"/>
</class>
</hibernate-mapping>
休眠.cfg.xml
<?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=D:\aaawypociny\mapowanie\mapowanie\baza.sdf</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
用户回购
class UserRepository
{
public void Add(User newUser)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(newUser);
transaction.Commit();
}
}
}
}
在我尝试添加时在 transaction.Commit
UserRepository repo = new UserRepository();
var ja = new User { FirstName = "Name", LastName = "Surname" };
repo.Add(ja);
VS给我
NHibernate.dll 中发生了“NHibernate.Exceptions.GenericADOException”类型的未处理异常
附加信息:无法插入:[mapowanie.Domain.User#8cafd9e5-0eda-4ccc-ba4a-f8935b68dfdc][SQL: INSERT INTO User (FirstName, LastName, Id) VALUES (?, ?, ?)]
我能做错什么?