RIA 服务中的自定义属性在客户端上不可用

发布于 2024-10-26 15:14:09 字数 2157 浏览 3 评论 0原文

我有一个名为 StatusUpdates 的实体。其中没有自我加入。但是我想包含一个 StatusUpdates 类型的 InternalStatusUpdates 列表(我再次提到数据库中没有自连接)。因此,我在同一命名空间中创建了一个分部类,并创建了一个名为 InternalStatusUpdates 的属性,并在其上包含 [DataMember] 属性。但还是没有出现在客户端。具体来说,这是我的部分类:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.Runtime.Serialization;
using System.ServiceModel.DomainServices.Server;
using System.ComponentModel.DataAnnotations;

namespace FMT.Data.Web
{
    public partial class StatusUpdate : EntityObject
    {

         private List<StatusUpdate> _internalListStatusUpdates = new List<StatusUpdate>();
         [DataMember]
         public List<StatusUpdate> InternalListStatusUpdates
         {
             get { return _internalListStatusUpdates; }
             set {
                 _internalListStatusUpdates = value;
                 OnPropertyChanged("InternalListStatusUpdates");
             }
         }
    }
}

有趣的是,如果我将 List 更改为 List,它就可以在客户端上使用!我该如何解决这个问题?

我想因为它是实体类型我必须指定[Ininclude]。当我这样做时,我收到以下错误:-

Invalid Include specification for member 'StatusUpdate.InternalListStatusUpdates'. Non-projection includes can only be specified on members with the AssociationAttribute applied.

然后我继续指定关联,所以现在我的属性看起来像:-

private List<StatusUpdate> _internalListStatusUpdates = new List<StatusUpdate>();
     [DataMember]
    [Include]
    [Association("internalUpdates", "StatusUpdatesId", "StatusUpdatesId")]
     public List<StatusUpdate> InternalListStatusUpdates
     {
         get { return _internalListStatusUpdates; }
         set {
             _internalListStatusUpdates = value;
             OnPropertyChanged("InternalListStatusUpdates");
         }
     }

其中 StatusUpdatesId 是我在 StatusUpdates 实体中的主键internalUpdates 只是一个任意选择的名称。现在构建已成功,并且该属性在客户端上可用,但我从服务器填充的数据在客户端上不可用。我该如何解决它?

提前致谢 :)

I have an entity called StatusUpdates. There is no self join in it. However i want to include a list of InternalStatusUpdates which is of type StatusUpdates (Again i would mention there is no self join in database). So i created a partial class in the same namespace and created a property named InternalStatusUpdates and included [DataMember] attribute on it. But it still doesn't appear on the client. This is my partial class to be specific :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.Runtime.Serialization;
using System.ServiceModel.DomainServices.Server;
using System.ComponentModel.DataAnnotations;

namespace FMT.Data.Web
{
    public partial class StatusUpdate : EntityObject
    {

         private List<StatusUpdate> _internalListStatusUpdates = new List<StatusUpdate>();
         [DataMember]
         public List<StatusUpdate> InternalListStatusUpdates
         {
             get { return _internalListStatusUpdates; }
             set {
                 _internalListStatusUpdates = value;
                 OnPropertyChanged("InternalListStatusUpdates");
             }
         }
    }
}

Interesting thing is if i change List<StatusUpdate> to List<string> it is available on the client! How do i solve this problem?

I thought because it is entity type i will have to specify [Include]. When i did that i get the following error :-

Invalid Include specification for member 'StatusUpdate.InternalListStatusUpdates'. Non-projection includes can only be specified on members with the AssociationAttribute applied.

Then i went ahead and specified association, so now my property looks like :-

private List<StatusUpdate> _internalListStatusUpdates = new List<StatusUpdate>();
     [DataMember]
    [Include]
    [Association("internalUpdates", "StatusUpdatesId", "StatusUpdatesId")]
     public List<StatusUpdate> InternalListStatusUpdates
     {
         get { return _internalListStatusUpdates; }
         set {
             _internalListStatusUpdates = value;
             OnPropertyChanged("InternalListStatusUpdates");
         }
     }

where StatusUpdatesId is my primary key in StatusUpdates Entity and internalUpdates is just a arbitary name chosen. Now the build is successfull and the property is available on the client but the data that i populate from server is not available on the client. How do i solve it?

Thanks in advance :)

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

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

发布评论

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

评论(2

合久必婚 2024-11-02 15:14:09

AssociationAttribute 中的第三个参数是列表元素中外键属性的名称。请务必记住,RIA 服务将实体放入其相应的 EntitySet中,然后对主键和外键应用过滤器,而不是使用对其他对象的真实引用。

在给定的情况下,您可能必须为列表元素定义属性“ParentUpdatesId”,并使用父 StatusUpdate 的主键填充该属性。

示例:

StatusUpdate su = new StatusUpdate { StatusUpdatesId = 123 };
StatusUpdate child1 = new StatusUpdate { StatusUpdatesId = 1001, ParentUpdatesId = 123 };
StatusUpdate child2 = new StatusUpdate { StatusUpdatesId = 1002, ParentUpdatesId = 123 };
su.InternalListStatusUpdates.Add(child1);
su.InternalListStatusUpdates.Add(child2);

您的关联将如下所示:

[Include]
[Association("internalUpdates", "StatusUpdatesId", "ParentUpdatesId")]
public List<StatusUpdate> InternalListStatusUpdates { ... }

The third parameter in AssociationAttribute is the name of the foreign-key property in the list elements. It is important to keep in mind that RIA Services puts entities in their corresponding EntitySet<T> and then applies filters on primary key and foreign key instead of using true references to the other objects.

In the given case you will probably have to define a property "ParentUpdatesId" for your list elements and fill that with the primary key of your parent StatusUpdate.

Example:

StatusUpdate su = new StatusUpdate { StatusUpdatesId = 123 };
StatusUpdate child1 = new StatusUpdate { StatusUpdatesId = 1001, ParentUpdatesId = 123 };
StatusUpdate child2 = new StatusUpdate { StatusUpdatesId = 1002, ParentUpdatesId = 123 };
su.InternalListStatusUpdates.Add(child1);
su.InternalListStatusUpdates.Add(child2);

Your Association would then look like this:

[Include]
[Association("internalUpdates", "StatusUpdatesId", "ParentUpdatesId")]
public List<StatusUpdate> InternalListStatusUpdates { ... }
小嗷兮 2024-11-02 15:14:09

我在搜索错误后来到此页面
“非投影包含只能在具有关联属性的成员上指定”

以防万一您也有同样的情况......
我的问题是,我出于习惯而包含了包含,但在这个特定的实例中,我通过链接表加入了多对多表,并且使用了 RIA 服务 M2M,因此通过投影在其他地方指定了特定的包含。
我收到的错误消息具有误导性,删除“包含”即可修复该问题。

I came to this page following a search on the error
"non projection includes can only be specified on members with the associationattribute"

Just in case you di likewise...
My problem was that I'd included the include out of habit, but in this particular instance I was joining a many to many table via a link table and was using RIA Services M2M so had specified the particular include elsewhere via a projection.
The error message I was getting was misleading, and removing the Include fixed it.

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