我正在使用 xtragrid 来保存、加载和修改数据。现在切换到 EF5 后,它就不起作用了。尝试将我的代码更改为local
和tobindinglist
,但数据库中没有任何更改。有什么建议么?
public partial class formKonstruksiyon : Form
{
public Tank_Analizor_DBEntities db;
public formKonstruksiyon()
{
InitializeComponent();
db = new Tank_Analizor_DBEntities();
}
private void formKonstruksiyon_Load(object sender, EventArgs e)
{
konstruksiyonBindingSource.DataSource = db.Konstruksiyon.Local.ToBindingList();
gridControl1.DataSource = konstruksiyonBindingSource.DataSource;
}
private void barButtonItemSave_ItemClick(object sender,
DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
db.SaveChanges();
LibStatic.ShowSuccessMessage();
}
catch (Exception ex)
{
LibStatic.ShowErrorMessage(ex);
}
}
private void silToolStripMenuItem_Click(object sender, EventArgs e)
{
gridView1.DeleteRow(gridView1.FocusedRowHandle);
}
}
更改后的一些更新:
konstruksiyonBindingSource.DataSource = db.Konstruksiyon.ToList();
private void barButtonItemSave_ItemClick(object sender,
DevExpress.XtraBars.ItemClickEventArgs e)
{
LibStatic.GridPostPendingRow(gridView1);
try
{
konstruksiyonBindingSource.DataSource = db.Konstruksiyon.Local.ToBindingList();
db.SaveChanges();
LibStatic.ShowSuccessMessage();
}
catch (Exception ex)
{
LibStatic.ShowErrorMessage(ex);
}
}
它有点保存:如果我只添加一个条目它不会保存,但如果我添加两个它会保存。这怎么可能呢?