【问题标题】:Entity Framework 6 and T4 - update WPF databindingsEntity Framework 6 和 T4 - 更新 WPF 数据绑定
【发布时间】:2014-09-09 21:38:27
【问题描述】:

我使用的是 Entity Framework 6,看起来 T4 只从数据库表中生成 POCO 类,没有太多附加功能。

例如,当我使用 EF4 时,我会自动获取 UI 更新

ItemsSource="{Binding SelectedParent.children}"

在添加到 Parent 的 EntityCollection 时更新:

 Dim c As New children With {.parent = Parent}
_context.children.Add(c)

或删除:

_context.children.Remove(someChildren)  

使用 EF 6,自动生成的类似乎只是 POCO。我不再看到例如 AssociationChanged 事件,也没有 OnPropertyChanging 和 OnPropertyChanged 事件。

在顶部,集合被定义为 HashSets

Public Overridable Property children As ICollection(Of children) = New HashSet(Of children )

在上下文中添加或删除实体对象时如何自动更新数据绑定? (我想要 EF4 功能回来!)

【问题讨论】:

  • 我错过了那个文档,但它救了我,谢谢。简而言之,我需要编辑 .tt 文件并将 ICollections 和 HashSets 更改为 ObservableCollections,以便 WPF 能够赶上更改。

标签: wpf entity-framework-6


【解决方案1】:

doc 解释了如何执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多