实体框架SaveChanges

时间:2012-01-13 09:56:43

标签: winforms entity-framework

我使用C#和Entity Framework创建了一个winforms应用程序。它包含两个数据库表:

  • Itemitem_id, item_name, item_number, item_group_id_fk
  • Item_groupsitem_group_id, item_group_name

数据源对象由Visual Studio生成。

before

问题是,如果我更改组合框并单击保存,则不会保存item表的数据,只保存item_groups表的数据。

after

这是代码:

public partial class Form1 : Form
{
    myEntities ve = new myEntities();

    public Form1()
    {
        InitializeComponent();
        itemBindingSource.DataSource = ve.items;
        item_group_nameComboBox.DataSource = ve.item_groups;
        item_group_nameComboBox.DisplayMember = "item_group_name";
        item_group_nameComboBox.ValueMember = "item_group_id";
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ve.SaveChanges();
    }
}

我做错了什么?

0 个答案:

没有答案