【问题标题】:bindingsource.AddNew method adds two record instead of 1bindingsource.AddNew 方法添加两条记录而不是 1
【发布时间】:2012-08-12 17:38:02
【问题描述】:

这个问题出现在带有实体框架的 Windows 窗体应用程序中。

源代码(V.S 2010): https://rapidshare.com/files/1553732530/WindowsFormsApplication8.rar

我有一个 “employes” 实体,它具有 ID、Name 字段和与“零或 1 TO 许多”多重性的自我关联。和两个导航属性 1-Manager 2-personnel

每个经理可以有零个或多个人员,每个人员可以有零个或多个经理。

在一个表单中,我有两个数据网格视图,一个用于经理,另一个用于第一个数据网格视图中当前选定经理的人员。到现在为止一切正常,但是当我调用下面的代码时,人员 BindingSource 添加了两条记录而不是一条记录

        employeBindingSource.AddNew();
        Employe p=(Employe)personnelBindingSource.AddNew();
        p.Manager = (Employe)employeBindingSource.Current;

有什么问题?

【问题讨论】:

  • 你发布你的发布实体上下文吗?顺便说一句,即使你释放它,也会发生内存泄漏
  • 我的问题是,当我设置employeBindingSource (p.Manager = (Employe)employeBindingSource.Current;) 的当前记录管理器时
  • personnelBindingSource 有两条新记录而不是 1 条

标签: c# visual-studio-2010 entity-framework-4 bindingsource


【解决方案1】:

这段代码可以正常工作

        employeBindingSource.AddNew();
        Employe p = new Employe();

        p.Manager = (Employe)employeBindingSource.Current;

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2018-12-02
    • 2014-09-01
    相关资源
    最近更新 更多