【问题标题】:Entity Framework equivalent of dataset's tableAdapter.FillBy实体框架等效于数据集的 tableAdapter.FillBy
【发布时间】:2012-01-22 20:02:49
【问题描述】:

对于 Winforms C# 应用程序,我正在寻找与数据集的 tableAdapter.Fill/tableAdapter.FillByBy 等效的 EF。

因为它们可重复用于重新填充 GridView(Windforms),可能使用不同的“where 子句”。

我知道现在使用具有不同参数的 EF 从 DB 填充/重新填充 GridView 的唯一方法:

this.myBindingSource.DataSource =  myNewSelectQueryObject;

“第一次填充”可以正常工作,但第二次会导致 DataSource 和 GirdView 无法编辑。 (尽管 GridView 的 BindingSource 不是“只读的”。)a,d EF.Refresh() 似乎不会更新可能在数据库中但不存在于“EF”中的记录。

感谢您的帮助。

PS:到目前为止,这是一些进展:

Refill(){
this.myDataEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, this.myDataEntities.myEntity);
this.myBindingSource.DataSource = myNewObjectQuery<...>;
this.myRadGridView.DataSource = this.myBindingSource.DataSource;
}

可选用:

this.myRadGridView.MasterTemplate.DataSource = this.myBindingSource.DataSource;

不确定这是否有用。

RadGridView 不再是“显然是只读的”了。

然后我想通过我的 BindingSource 添加一条记录: this.myBindingSource.AddNew(); 它没有出现在我的 RadGridView 中。 虽然我仍然可以添加记录并通过单击使用 RadGridView 中的“单击此处添加新行”工具来保存它。

所以 BindingSource 和网格之间存在一些不匹配。

【问题讨论】:

    标签: c# winforms entity-framework


    【解决方案1】:

    似乎解决方案是这样:

    Refill(){
    this.myDataEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, this.myDataEntities.myEntity);
    this.myBindingSource = new BindingSource();
    this.myBindingSource.DataSource = myNewObjectQuery<...>;
    this.myRadGridView.DataSource = this.myBindingSource;
    

    }

    重要的区别是“new Bindingsource()”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      相关资源
      最近更新 更多