在我的 Winform 项目中,我有一个简单的详细信息表单,我们可以在其中添加新的、编辑和保存持久对象,直到这里一切正常。
编辑控件是通过from构造函数中的代码绑定的,第一次创建的时候也是通过form构造函数传递的第一个新对象
现在我想实现一个Save and New方法,但没有成功
我试过了,假设 tbVehicule 是对象类,theVehicule是我的持久对象,而 frmVehicule 是我的详细信息表格
// Form Constructor
public frmVehicule(tbVehicule theVehicule)
: this() {
this.theVehicule = theVehicule;
// method to bind all controls
bindingFields();
}
// Save and new method
private void barBtnSaveNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.Validate();
theVehicule.Save();
theVehicule = new tbVehicule(theVehicule.Session);
}
该过程应该类似于其他 ORM,如 EF 或 Hibernate