WCF Ria cyclic references

19 posts, 1 answers
  1. Kristof
    Kristof avatar
    7 posts
    Member since:
    Apr 2009

    Posted 02 Jul 2011 Link to this post

    For a project I have to use a legacy database with some cyclic references. The entities are generated as expected, but when I try to use the entities through a WCF Ria service, I got the following error on tables containing cyclic references:

    There was an error while trying to serialize parameter http://tempuri.org/:GetPublicationPagesResult. The InnerException message was 'Object graph for type 'xxx.Entities.TblPublicationPage' contains cycles and cannot be serialized if reference tracking is disabled.

    After some digging I found that I just can decorate the entities generated by the RLinq file with the IsReference. I did this by using a Metadata class. One disadvantages of doing this, is that I have to put DataMember attributes on all properties. Else the client doesn't see the properties. Isn't there an eleganter solution for this problem? And not by using other DTO's to send over the wire?

    [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; }
        }
    }

     
    I found the following thread to add the DataServiceKey to ADO entities. But if I edit these templates my entities still don't have that attribute. When I change the Specific.ttinclude I can get the DataContract(IsReference = true) attribute but I don't manage to translate this snippet to ttinclude :

    [DataServiceKey#if($multipleField)(new string[]{"$(pkProperties)"})#end#if($singleField)("$(pkProperty)")#end]

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 07 Jul 2011 Link to this post

    Hi Kristof,

     The most elegant way would be editing the code generation. We are about to release a new ria wizard that will generate the metadata classes for you and you will be able to edit the templates there as it will be much easier.

    All the best,
    Petar
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Kristof
    Kristof avatar
    7 posts
    Member since:
    Apr 2009

    Posted 12 Jul 2011 Link to this post

    When will this new ria wizard will be available?
  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 13 Jul 2011 Link to this post

    Hi Kristof,

     The new RIA wizard has been introduced with Q2 released today. However the functionality that provides metadata generation will be available no early than our service pack.
    Can you please share with us what do you expect to be automatically generated? This way we will be able to add any missing functionality that we have possibly not though of.

    Greetings,
    Petar
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Kristof
    Kristof avatar
    7 posts
    Member since:
    Apr 2009

    Posted 15 Jul 2011 Link to this post

    Like I said at the start of this thread, I have to use a SQL database that has cyclic references. In my Domain Model these cyclic references are also included. Now when I try to retrieve data from my Silverlight client through the generated WCF Ria Domain Service. I get exceptions thrown that there are cyclic references.
    To fix this I need to add to all entities a metadata class, copy all properties decorate them with [DataMember] attribute. And put these attributes on the class level: (This for 14 entities for around 500 properties in total)

    [DataContract(IsReference = true)]
    [DataServiceKey("PublicationPageID")]

    There should be an option the generate these attributes automaticly. 

    Also for retrieving the related objects (through there relations), I have to manually add [Include] and the [Association] tags
    too. When using OpenAccess with plain WCF, I don't have these problems and I can just work with FetchStrategy objects...
    I also read that there where issues when setting relations and objects on these generated entities (thread)

    Or am I missing something in the concept, which is also possible :-)
  7. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 21 Jul 2011 Link to this post

    Hello Kristof,

    No, you are 100% right and you are not missing anything. We do have plans to include those features to be automatically generated. We had plans to include them even for the release but some last seconds issues were found and we had to postpone it for the service pack. I might be able however to provide you with a custom code generation template that will auto generate the buddy classes with the required attributes for you. Please tell me if that will work for you. 

    Best wishes,
    Petar
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  8. Frederik
    Frederik avatar
    4 posts
    Member since:
    Oct 2010

    Posted 21 Jul 2011 Link to this post

    Yes, that would be great!
  9. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 26 Jul 2011 Link to this post

    Hello Frederik,

     Great. I will post here with a link to the templates as soon as they are prepared to work for your case. 

    Best wishes,
    Petar
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  10. Kristof
    Kristof avatar
    7 posts
    Member since:
    Apr 2009

    Posted 01 Aug 2011 Link to this post

    Do you have an estimate when dees templates will be available?
  11. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 03 Aug 2011 Link to this post

    Hello Kristof,

     The templates will be available by the end of the week latest.

    Greetings,
    Petar
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  12. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 12 Aug 2011 Link to this post

    Hello Kristof,

     Please find the tt templates attached to this thread. Steps you will need to follow to make it working:
    1. Add the template in your project where you would like to generate the metadata classes.
    2. Open the template and on the 11th row replace the path to point to your local version of the Telerik.Common.UI assembly.
    3. On the 12th row replace the version number of the OpenAccess assembly with the one you have locally on your machine.
    4. On the 43th row you will see that there is a path pointing to an rlinq file. Replace this path with one pointing to your rlinq file. This is needed for us to load the metadata container and generate the required code.
    5. On the 42th row Add the class names for which you would like to see metadata generated. Please not that the classes needs to be added in the string array.
    6. Save the template.

    This should be all. 
    Please have in mind that those templates are still in Beta and there is a possibility that there might be some small issues with them(although this is not likely). The template is easily tweakable so if you need any attributes generated automatically please write to us and we will include them. 
    We are looking forward to your reply.

    All the best,
    Petar
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  13. Frederik
    Frederik avatar
    4 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2011 Link to this post

    I added the template and it is generating the metadata classes correctly. Still we are missing the attributes, like in the sample above:

    [DataContract(IsReference = true)]
    [DataServiceKey("BlockID")]

    where "BlockID" is the primary key.
    These attributes are for the top level (on top of the class)

    and

    [DataMember]

    On every internal metadata properties.

  14. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 16 Aug 2011 Link to this post

    Hi Frederik,

    I modified the T4 template in order to enable the code generation for the attributes that you ask for.
    Hope that helps. If any other questions arise, do not hesitate to contact us back.

    Regards,
    Damyan Bogoev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  15. Frederik
    Frederik avatar
    4 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2011 Link to this post

    These are working perfectly tnx!

    One question: why don't Openaccess and WCF Ria generate the association and include attributes automaticly or through a wizard/diagram? Now I still have to add manually all relations between the entities and therefore need to change the generated templates.
  16. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 16 Aug 2011 Link to this post

    Hello Frederik,

    Please find the template updated. Now it should generated the IncludeAttribute and AssociationAttribute for the relations between the classes.
    Hope that helps.

    Greetings,
    Damyan Bogoev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  17. Frederik
    Frederik avatar
    4 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2011 Link to this post

    Tnx, it is working perfect... 

    I added a few missing namespaces and added a namespace to the generated code.

    <#@ import namespace="Telerik.OpenAccess.Metadata.Relational"#>
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Data.Services.Common;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel.DomainServices.Server;

    Add namespace and indentation:
    string[] queriableTypes = new string[] { "zzz" };
    string rlinqFilePath = @"yyy";
    string myNamespace = "myNameSpace";
     
    private void GenerateBuddyClasses()
    {
        this.WriteLine("namespace "+ myNamespace);
        this.WriteLine("{");
        PushIndent("\t");
        MetadataContainer container = RlinqReaderHelper.GetContainerFromXml(rlinqFilePath);
        foreach(MetaPersistentType type in container.PersistentTypes)
        {
                if(queriableTypes.Contains(type.Name))
                {
                    this.GenerateMetadataClass(type);
                }
        }
        PopIndent();
        this.WriteLine("}");
    }

  18. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 16 Aug 2011 Link to this post

    Hello Frederik,

    I am glad to see that you managed to achieve the goal.
    If any other questions arise, do not hesitate to contact us back.

    Best wishes,
    Damyan Bogoev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  19. Brett
    Brett avatar
    1 posts
    Member since:
    Apr 2012

    Posted 24 May 2012 Link to this post

    I am getting this same error:

    There was an error while trying to serialize parameter http://tempuri.org/:xml_definition.
    The InnerException message was 'Object graph for type
    '<snip>namespace.classname</snip>.Picklist_WSDLState'
    contains cycles and cannot be serialized if reference tracking is disabled.'. 
    Please see InnerException for more details.

    Please note, the InnerException is null.

    I have the most current full version of OpenAccess ORM installed  (as of May 2012).

    Would your template have been integrated into the Telerik OpenAccess ORM product or does this support thread still apply?

    If it does, what are the instructions to install the template into my project?

    Brett
  20. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 May 2012 Link to this post

    Hello Brett,

    You can set the IsReference on the DataContract definition, which will force the serializer to generate XML elements with the appropriate reference attributes.

    Additional helpful information can be found in this blog post.

    Hope that helps.

    All the best,

    Damyan Bogoev
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top
DevCraft banner