【问题标题】:Linq to Entities Binding, Filtering and Editing in WinFormsLinq to Entities Binding, Filtering and Editing in WinForms
【发布时间】:2009-04-16 19:32:06
【问题描述】:

1) 绑定到以下内容会填充只读 WinFrms 网格:

    Dim query = (From profile _
              In db.profile _
              Where profile.employee.employeeId = employeeID _
              Select profile.description)

    Me.DataGridView.DataSource = profileQueryList

2) 绑定到实体本身使 WinForms 网格可编辑,但未过滤:

    Me.DataGridView.DataSource = db.profile

我需要将#1 的过滤功能与#2 的可编辑功能相结合的东西。

【问题讨论】:

    标签: binding datagrid .net-3.5 linq-to-entities


    【解决方案1】:

    尝试使用明确的ToList() 调用。

    Me.DataGridView.DataSource = query.ToList()
    

    我猜想否则只有查询的表达式树被绑定,实体只是按需获取。

    【讨论】:

    • 你试过在控件和集合之间插入一个BindingSource吗?
    【解决方案2】:

    找到了解决方案!它记录在:
    Linq to Entities Filtering an Entity Dynamic/Strongly Typed

    【讨论】:

      【解决方案3】:

      不要直接绑定到可查询对象。相反,您需要通过 EntityDataSource 类。请特别注意this article on how to filter data with this control

      【讨论】:

      • EntityDataSource 是 System.Web.UI.Webcontrols 的一部分。我在 Winforms 环境中工作。有没有等价物?
      • 海报询问 WinForms,而不是 ASP.NET Web 表单
      猜你喜欢
      • 2010-10-25
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      相关资源
      最近更新 更多