Why there is no any tutorial about binding NHibernate
to DataGridView
in Winforms
. Only I want to use it?
I know that this is matter of binding collection to DataGridView. But I have problems with making CRUD.
I have database SQLite+table with mapping:
<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>
Code that works.
Employee new_employee =
new Employee() { first_name = "test1", last_name = "test3", login = "login1" };
session.Save(new_employee);
session.Commit();
But if I bind to DataGridView and use grid to insert a new row:
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);
}
After session.Commit()
I get an error: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect).
In logs i see that NH sends UPDATE for that new row. Should be insert.