【发布时间】:2014-11-16 16:11:59
【问题描述】:
我正在关注本教程http://msdn.microsoft.com/pl-PL/data/jj682076。我想从我的 Context 中加载特定类别,然后创建一个 DataGrid 并将其与该类别的 Products 属性绑定。我希望能够在 DataGrid 上添加、编辑和删除产品 我一直在尝试使用此代码:
context.Cetegories.Where(c => c.categoryID == _category.categoryID ).Select(c => c.Products).Load();
this.productsBindingSource.DataSource = _context.Categories.Local.ToBindingList();
productsBindingSource 是我的绑定源,DataGrid 由设计器生成,绑定源为 DataSource。
我怎样才能做到这一点?
我还想直接从上下文加载产品并将它们绑定到 DataGrid
_context.Products.Where(c => c.categoryID == _category.categoryID).Load();
但是当我想直接从网格中为该类别添加新产品时,fk 会出现问题,因为我不知道如何为新项目正确设置它。
【问题讨论】:
标签: c# winforms entity-framework datagrid