This is a migrated thread and some comments may be shown as answers.

WCF Ria cyclic references

18 Answers 146 Views
Integration with other products
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kristof
Top achievements
Rank 1
Kristof asked on 02 Jul 2011, 04:30 PM

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]

18 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 07 Jul 2011, 08:41 AM
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!

0
Kristof
Top achievements
Rank 1
answered on 12 Jul 2011, 08:40 AM
When will this new ria wizard will be available?
0
PetarP
Telerik team
answered on 13 Jul 2011, 05:25 PM
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!

0
Kristof
Top achievements
Rank 1
answered on 15 Jul 2011, 12:32 PM
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 :-)
0
PetarP
Telerik team
answered on 21 Jul 2011, 03:23 PM
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!

0
Frederik
Top achievements
Rank 1
answered on 21 Jul 2011, 03:49 PM
Yes, that would be great!
0
Accepted
PetarP
Telerik team
answered on 26 Jul 2011, 02:57 PM
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!

0
Kristof
Top achievements
Rank 1
answered on 01 Aug 2011, 08:21 AM
Do you have an estimate when dees templates will be available?
0
PetarP
Telerik team
answered on 03 Aug 2011, 03:32 PM
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 >>

0
PetarP
Telerik team
answered on 12 Aug 2011, 04:17 PM
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 >>

0
Frederik
Top achievements
Rank 1
answered on 16 Aug 2011, 08:28 AM
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.

0
Damyan Bogoev
Telerik team
answered on 16 Aug 2011, 09:56 AM
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 >>

0
Frederik
Top achievements
Rank 1
answered on 16 Aug 2011, 10:33 AM
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.
0
Damyan Bogoev
Telerik team
answered on 16 Aug 2011, 02:37 PM
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 >>

0
Frederik
Top achievements
Rank 1
answered on 16 Aug 2011, 04:02 PM
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("}");
}

0
Damyan Bogoev
Telerik team
answered on 16 Aug 2011, 04:50 PM
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 >>

0
Brett
Top achievements
Rank 1
answered on 24 May 2012, 05:01 PM
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
0
Damyan Bogoev
Telerik team
answered on 28 May 2012, 12:41 PM
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!
Tags
Integration with other products
Asked by
Kristof
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Kristof
Top achievements
Rank 1
Frederik
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Brett
Top achievements
Rank 1
Share this question
or