首页 文章

WCF Ria服务和循环引用

提问于
浏览
1

我正在使用具有一些循环引用的遗留数据库 . 当我从SL4客户端使用我的Ria服务时 . (通过我的ORM映射器生成的实体)我收到以下错误:

尝试序列化参数http://tempuri.org/:GetPublicationPagesResult时出错 . InnerException消息是'Object graph for type ' xxx.Entities.TblPublicationPage'包含循环,如果禁用参考跟踪,则无法序列化 .

[Query]
public IQueryable<TblPublicationPage> GetPublicationPages(int publicationId)
{
    return this.PublicationLogic.Value.GetPublicationPages(publicationId);
}

我知道如何通过CyclicReferencesAware属性或IsRefence = true为普通WCF启用它 . 但我无法弄清楚如何使用WCF Ria Services执行此操作 .

2 回答

  • 0

    我现在更好地理解WCF Ria服务,我只是尝试修复它,就像我在普通的WCF中做的那样,并为我生成的实体添加了一个元数据:

    [DataContract(IsReference = true)]
    [DataServiceKey("PublicationPageID")]
    [DebuggerDisplay("PublicationPageID: {PublicationPageID}")]
    [MetadataType(typeof(TblPublicationPageMetadata))]
    public partial class TblPublicationPage
    {
        internal sealed class TblPublicationPageMetadata
        {
            [DataMember]
            public int PublicationPageID { get; set; }
        }
    }
    

    此时唯一的缺点是我必须使用[DataMember]属性装饰元数据类中的每个属性...

  • 0

    使用[CyclicReferencesAware(true)]

相关问题