【发布时间】: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 能够赶上更改。