Silverlight 4 实体框架将 DataGridColumn 绑定到导航属性
我正在使用 EF4,并且在我的域模型中有一个名为“应用程序”的实体。应用程序有一个名为“状态”的导航属性。状态实体包含 2 个字段:StatusID 和 StatusName。 我正在显示一个显示应用程序详细信息的数据网格。我已使用 [Include] 属性装饰了应用程序元数据,并且还修改了 GetApplicationsQuery 以具有 .Include("status") 语句。网格的 ItemsSource 是使用 Linq 查询在代码中设置的。
如果我将 DataGrid 上的 AutoGenerateColumns 设置为 true,则状态列指示存在状态对象,因此看起来包含工作正常。 我现在想将 AutoGenerateColumns 设置为 false 并手动构建数据网格(仅显示几列),但我找不到如何将 StatusName 字段(属于状态导航属性)绑定到其中一列。下面的代码显然不起作用,因为我有效地将状态列绑定到对象,但是绑定到导航属性上的字段的正确方法是什么?
<telerik:GridViewDataColumn Header="App Name" DataMemberBinding="{Binding AppName}"/>
<telerik:GridViewDataColumn Header="Commentary" DataMemberBinding="{Binding Commentary}"/>
<telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding **status**}"/>
我尝试绑定到 status.StatusName,但我现在只是猜测。任何帮助将不胜感激。
谢谢
我
I'm using EF4 and have a entity in my domain model called Applications. Applications has a navigation property called Status. The Status Entity contains 2 fields, StatusID and StatusName.
I'm displaying a DataGrid that shows the details of Applications. I have decorated the Application Metadata with the [Include] attribute, and have also modified the GetApplicationsQuery to have an .Include("status") statement. The ItemsSource for the grid is set in code using a Linq query.
If I set AutoGenerateColumns on my DataGrid to true, the status column indicates that there is a status object, so it looks like the Includes are working correctly.
I now want to set AutoGenerateColumns to false and manually build the datagrid (to only show a few columns), but I can't find how to bind the StatusName field (belonging to the status navigation property) to one of the columns. The code below obviously doesn't work as i'm effectively binding the Status column to an object, but what is the correct way to bind to a field on a navigation property?
<telerik:GridViewDataColumn Header="App Name" DataMemberBinding="{Binding AppName}"/>
<telerik:GridViewDataColumn Header="Commentary" DataMemberBinding="{Binding Commentary}"/>
<telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding **status**}"/>
I've tried binding to status.StatusName, but i'm just guessing now. Any help would be appreciated.
Thanks
M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题了。
我没有使用 DomainService 中定义的查询(在本例中为 GetApplicationsQuery),而是使用 Linq 查询(来自 in ctx.applications where .......)。
生成的 GetApplicationsQuery 添加了 .Include("status") 语句,但我的手动 Linq 查询没有添加。
我将 DataGrid ItemsSource 设置为使用 GetApplicationsQuery().Where(a=>.... 然后我就能够使用 2 部分名称 status.StatusName 访问导航属性
。
Found the problem.
Instead of using the queries defined in the DomainService (GetApplicationsQuery in this instance), I was using a Linq query (from a in ctx.applications where ..........).
The generated GetApplicationsQuery had the .Include("status") statements added, but my manual Linq query didn't.
I set my DataGrid ItemsSource to use the GetApplicationsQuery().Where(a=>.... and I was then able to access the navigation property using the 2 part name, status.StatusName.
M