SubSonic 3 中的 WPF 与外键的绑定
在使用 Active Record 的 WPF 和 SubSonic 2 中,我能够绑定到一个表中的行中的属性,并轻松地遵循外键引用(返回外键行表示形式的属性)来绑定到外键表中的字段。 有了 SubSonic 3 和 ActiveRecord,我不太确定如何(轻松地)做到这一点。 看起来外键引用返回 IQueryable(Of T) ,它没有获取外键行的属性。 然而,有一些函数(First 和 Single)可以实现我想要的功能。
例如,假设我有一个 Employee 表,其中包含对 Department 表的外键引用,在 SubSonic 2 中,我能够执行以下操作:
在代码中:
MyGrid.ItemsSource = New EmployeeCollection().Load()
在 xaml 中:
<grid:DataGrid name="MyGrid">
<grid:DataGrid.Columns>
<grid:DataGridTextColumn Header="Employee" Binding="{Binding Path=EmployeeName}" />
<grid:DataGridTextColumn Header="Department" Binding="{Binding Path=Department.DepartmentName}" />
</grid:DataGrid.Columns>
</grid:DataGrid>
在 SubSonic 3 中,我无法找出与绑定到 DepartmentName,即
Binding="{Binding Path=Department.DepartmentName}"
如何在 SubSonic 3 中完成此操作? 提前致谢。
In WPF and SubSonic 2 using Active Record, I was able to bind to properties in rows from one table and easily follow the foreign key references (properties that returned the foreign key row representation) to bind to fields in the foreign key table. With SubSonic 3 and ActiveRecord, I'm not quite sure how to do this (easily) anymore. It looks like the foreign key references return IQueryable(Of T) which does not have a property to get the foreign key row. There is, however, are functions (First and Single) which accomplish what I would like.
For example, let's say I have an Employee table with a foreign key reference to a Department table, in SubSonic 2, I was able to do something like:
In code:
MyGrid.ItemsSource = New EmployeeCollection().Load()
In xaml:
<grid:DataGrid name="MyGrid">
<grid:DataGrid.Columns>
<grid:DataGridTextColumn Header="Employee" Binding="{Binding Path=EmployeeName}" />
<grid:DataGridTextColumn Header="Department" Binding="{Binding Path=Department.DepartmentName}" />
</grid:DataGrid.Columns>
</grid:DataGrid>
In SubSonic 3, I cannot figure out the equivalent to the binding to the DepartmentName, i.e.
Binding="{Binding Path=Department.DepartmentName}"
How do I accomplish the this in SubSonic 3? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到两个选项:
1) 修改 T4 模板以提供您期望的属性。 这可能看起来更自然,但我不确定您最终不会在不合适的模型上得到这些属性。
2) 使用 ObjectDataProvider 绑定到模型上的方法。
I see two options:
1) Modify the T4 templates to provide the properties you are expecting. This may seem more naturally, but I'm not sure you won't end up with those properties on models where they aren't appropriate.
2) Use the ObjectDataProvider to bind to methods on your models.
我相信在 WPF 中,您应该将集合绑定到可观察集合 - 请参阅 从 SubSonic 2.2 集合创建 WPF ObservableCollection
I beleive in WPF that you should bind a collection to an observable collection - see Create A WPF ObservableCollection From A SubSonic 2.2 Collection