请为此方案寻求解决方案(请提供代码):
每当我保存实体Y的更改时,它也将应用于实体X
我的示例代码:
1-加载并更新客户端X:
public static void UpdateClient(ModeleContainer GStock, Modele.Client Client)
{
try
{
using (frmClient frmClient = new frmClient(GStock, Client))
{
if (frmClient.ShowDialog() == DialogResult.Cancel)
{
GStock.UndoDbContext();
}
else
if (frmClient.ShowDialog() == DialogResult.OK)
GStock.SaveChanges();
}
}
}
catch (Exception e)
{
Methods.DealWithException(e);
}
}
2-加载并更新类别Y(由frmClient表单' s调用)
public static void UpdateCategorie(ModeleContainer GStock, Modele.Category Category)
{
try
{
using (frmCategorie frmCategorie = new frmCategorie(GStock, Category ))
{
if (frmCategorie.ShowDialog() == DialogResult.OK)
{
// CategorieBindingSource is a public BindingSource
frmCategorie.CategorieBindingSource.EndEdit();
GStock.SaveChanges();
}
else
GStock.UndoDbContext();
}
}
catch (Exception e)
{
Methods.DealWithException(e);
}
}
3- GStock是所有表单的共享DbContext,用于跟踪更改