【问题标题】:Master detail using EF 4 in Windows Forms在 Windows 窗体中使用 EF 4 掌握详细信息
【发布时间】:2012-04-26 23:41:00
【问题描述】:

使用 Northwind 数据库作为实体数据模型,我从数据源窗口中拖出 2 个包含 Orders 和 Order_details 的 datagridview 控件,并将它们拖放到一个 windows 窗体上。运行项目时,我只得到了 Orders Gridview 填充,而不是排序。接下来是我在表单加载事件中使用的代码:

        using(NorthwindEntities context = new NorthwindEntities())
        {

        ordersDataGridView.DataSource = context.Orders;
        ordersBindingSource.Sort = "CustomerID ASC";

        order_DetailsDataGridView.DataSource = order_DetailsBindingSource;

        }

如何使details Grid显示与所选订单实体相关的项目,以及如何对订单网格进行排序?谢谢。

【问题讨论】:

  • 什么是order_DetailsBindingSource?它来自哪里?
  • order_DetailsBindingSource 是在表单上拖放订单数据网格时自动生成的。
  • 你能给我们看看order_detailsbindingsource和ordersdatagridview的标记代码吗?

标签: c# winforms entity-framework linq-to-entities


【解决方案1】:
  1. 详细显示选择订单的相关项目网格应该自动工作,无需任何添加代码。请检查您的详细信息绑定源的 BindingSource.DataSource 属性。它应该包含您的主绑定源的名称。

  2. 您可以使用 linq 查询对订单进行排序:

    ordersDataGridView.DataSource = context.Orders.OrderBy(o => o.CustomerID);

【讨论】:

  • 1.我检查了我的详细信息绑定源的 BindingSource.DataSource 属性。它已经包含主绑定源 (ordersBindingSource) 的名称。
  • 1.仍然没有显示数据。 2.你第二部分的答案是对的,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-21
  • 2013-02-15
  • 2019-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多