爲什麼沒有關於綁定NHibernate
到在Winforms
的任何教程。只有我想使用它? 我知道這是綁定到DataGridView集合的問題。但是我在製作CRUD時遇到了問題。Nhibernate綁定到DataGridView
我有數據庫SQLite的+表映射:該作品
<class name="Employee" table="emplyees" lazy="true">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="first_name" not-null="true"></property>
<property name="last_name" not-null="true"></property>
<property name="login" not-null="true"></property>
<property name="sid"></property>
</class>
代碼。
Employee new_employee =
new Employee() { first_name = "test1", last_name = "test3", login = "login1" };
session.Save(new_employee);
session.Commit();
但是,如果我綁定的DataGridView和使用網格插入新行:
transaction = session.BeginTransaction();
employees = (from e in session.Linq<Employee>() select e).ToList<Employee>();
this.employeeBindingSource.DataSource = employees;
private void employeeDataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
Employee new_employee = (Employee)this.employeeBindingSource.Current;
session.Save(new_employee);
}
session.Commit()
後,我得到一個錯誤:Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect).
日誌中我看到,NH將更新該新行。應該插入。
公共屬性應該以這種格式=> UpperCase。所以FirstName不是first_name。 **標準**您知道... – gdoron 2012-02-05 12:12:24
感謝您的建議 – userbb 2012-02-05 12:23:29
答案如何? – gdoron 2012-02-05 12:27:43