我使用C#和Entity Framework创建了一个winforms应用程序。它包含两个数据库表:
Item
(item_id, item_name, item_number, item_group_id_fk
)Item_groups
(item_group_id, item_group_name
)数据源对象由Visual Studio生成。
问题是,如果我更改组合框并单击保存,则不会保存item
表的数据,只保存item_groups
表的数据。
这是代码:
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();
}
}
我做错了什么?