数据网格中的导航属性字段

发布于 2024-12-10 15:29:12 字数 2454 浏览 0 评论 0原文

我有一个 silverlight 项目,需要一个数据网格来显示数据库模型中的数据。为简单起见,我将使用以下模型。

数据网格应显示已提交但未批准的文章。每个“文章提交”都有一个“作者”,可以通过导航属性访问。

我需要一个数据网格,其中包含“文章提交”和“作者”表中的字段。

<sdk:DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding ElementName=articleApplicationDataSource,Path=Data}" 
Name="articleSubmissionDataGrid" 
RowDetailsVisibilityMode="VisibleWhenSelected">
   <sdk:DataGrid.Columns>  
   ...some column template definitions

      <!--THIS LOADS FINE!-->
      <sdk:DataGridTextColumn x:Name="articleTitleColumn"
      Binding="{Binding Path=Title}" Header="Title" />

      <!--THIS DOESN'T-->
      <sdk:DataGridTextColumn x:Name="authorNameColumn"
      Binding="{Binding Path=Author.Name}" Header="Name" />

  </sdk:DataGrid.Columns>
</sdk:DataGrid>

因此,假设我的“作者”实体正在加载到“articleSubmissionDataSource”中(似乎是)。我的绑定 path=Author.Name 是通过导航属性访问“作者”实体的正确方法吗?

顺便提一句: 'articleApplicationDataSource' 是通过像这样的 'riaControl' 在 xaml 中设置的。

<riaControls:DomainDataSource AutoLoad="True" 
d:DesignData="{d:DesignInstance my1:ArticleSubmission, CreateList=true}" Height="0"
LoadedData="roleApplicationDomainDataSource_LoadedData"
name="articleSubmissionDomainDataSource" 
QueryName="GetArticleSubmissionsQuery" Width="0" LoadSize="500">
     <riaControls:DomainDataSource.DomainContext>
               <my:OrganizationContext />
     </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

另外,我注意到我的域服务的 GetArticleSubmissions 方法返回“作者”导航属性的有效信息。但是,当我检查“LoadedDataEventArgs e”时,“Author”导航属性似乎设置为 null。

中的代码

public IQueryable<RoleApplication> GetRoleApplications()
{
     return this.ObjectContext.ArticleSubmissions.Include("Person");         
}

这是我的域服务文章提交元数据

internal sealed class ArticleSubmissionMetadata
    {

        // Metadata classes are not meant to be instantiated.
        private ArticleSubmissionMetadata()
        {
        }

         [Include]
        public Author Author { get; set; }

        public DateTime Date { get; set; }

        public int ID { get; set; }

        public int AuthorID { get; set; }

        public string Title { get; set; }
    }
}

,请,请,请帮忙。如果您不明白我发布的一大堆代码,那么只需向我指出一些参考资料,这些参考资料解释了如何将实体和导航属性实体绑定在一个地方。

另外,如果您发现代码有任何错误的做法,请告诉我。这些都不是我写的,但我被赋予了让它发挥作用的任务。我是银光新手。

I have a silverlight project where I need a datagrid to display data from my database model. For simplicity ill use the following model.

The data grid should display articles that have been submitted but not approved. Each 'Article Submission' has an 'Author' that can be accessed through a navigation property.

I need to have a data grid that has fields from both the 'Article Submission' and the 'Author' tables.

<sdk:DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding ElementName=articleApplicationDataSource,Path=Data}" 
Name="articleSubmissionDataGrid" 
RowDetailsVisibilityMode="VisibleWhenSelected">
   <sdk:DataGrid.Columns>  
   ...some column template definitions

      <!--THIS LOADS FINE!-->
      <sdk:DataGridTextColumn x:Name="articleTitleColumn"
      Binding="{Binding Path=Title}" Header="Title" />

      <!--THIS DOESN'T-->
      <sdk:DataGridTextColumn x:Name="authorNameColumn"
      Binding="{Binding Path=Author.Name}" Header="Name" />

  </sdk:DataGrid.Columns>
</sdk:DataGrid>

So assuming my 'Author' entity is getting loaded into 'articleSubmissionDataSource' (It seems to be). Is my binding path=Author.Name the correct way to access the 'Author' entity through the navigation property?

BTW:
'articleApplicationDataSource' is being set in xaml by a 'riaControl' like this.

<riaControls:DomainDataSource AutoLoad="True" 
d:DesignData="{d:DesignInstance my1:ArticleSubmission, CreateList=true}" Height="0"
LoadedData="roleApplicationDomainDataSource_LoadedData"
name="articleSubmissionDomainDataSource" 
QueryName="GetArticleSubmissionsQuery" Width="0" LoadSize="500">
     <riaControls:DomainDataSource.DomainContext>
               <my:OrganizationContext />
     </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

Also, I've noticed my GetArticleSubmissions method of my domain service returns valid information for the 'Author' Navigation Property. However when I examine the 'LoadedDataEventArgs e' the 'Author' Navigation Property seems to be set to null.

Here's the code in my domain service

public IQueryable<RoleApplication> GetRoleApplications()
{
     return this.ObjectContext.ArticleSubmissions.Include("Person");         
}

Metadata for ArticleSubmission

internal sealed class ArticleSubmissionMetadata
    {

        // Metadata classes are not meant to be instantiated.
        private ArticleSubmissionMetadata()
        {
        }

         [Include]
        public Author Author { get; set; }

        public DateTime Date { get; set; }

        public int ID { get; set; }

        public int AuthorID { get; set; }

        public string Title { get; set; }
    }
}

Please, Please, Please help. If you don't understand the big mess of code I've posted then just point me to references that explain how to bind a entity and a navigation property entity together in one place.

Also if you notice any practices that are wrong the code please let me know. I didn't write any of this but I'm been given the task of making it work. I'm new to silverlight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-12-17 15:29:12

...事实证明我上面列出的所有内容都是正确的。我的问题是我的 .include("Author) 查询错误!!!!我会将其保留为示例,以防其他人遇到此问题。我发现很难找到示例文本。

如果您来这里如需帮助,请确保您的域服务中包含 include("Person")。

... Turns out everything I listed above is correct. My Problem is I had my .include("Author) on the wrong query!!!! I'll leave this up as a sample in case anyone else has this issue. I found it hard to find example text.

If your coming here for help make sure you have the include("Person") in your domain service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文