Click here to Skip to main content
15,887,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an entity CustomerActivityReport which I'm trying to submit to the server via WCF. On the server end I'm using the repository + UOW patterns to update/insert the entity into the db.

CustomerActivityReport has a many to many relationship to another entity LookupValue. When I try and submit an instance of CustomerActivityReport, the DataContractSerializer throws the error: "Object graph for type 'FixupCollection<customeractivityreport>' contains cycles and cannot be serialized if reference tracking is disabled". I am getting this error even when I don't set the relationship on the LookupValue entities.

To get around this I've tried applying [DataContract(IsReference = true)] to both the entities in question and also to FixupCollection. But then I get different problems.

Has anybody else run into similar problems when trying to submit related entities over WCF?

Thanks in advance for any replies.

Ryan
Posted

1 solution

I couldn't get this working with FixupCollection, and so I've had to submit all my entity collections as standard Collection, and then add logic server end to change them back into FixupCollection.

Client:
convertedCustomerActivityReport.LookupValues = new Collection<LookupValue>()


Server:
public virtual ICollection<LookupValue> LookupValues
{
    get
    {
        if (_lookupValues == null || _lookupValues is Array)
        {
            var newCollection = new   FixupCollection<LookupValue>();
            newCollection.CollectionChanged += FixupLookupValues;
            newCollection.AddRange(_lookupValues);
            _lookupValues = newCollection;
        }
        return _lookupValues;
    }


I've also added an AddRange method to FixupCollection:

/// <summary>
/// Adds multiple items.
/// </summary>
/// <param name="items">The items to add.</param>
public void AddRange(IEnumerable<t> items)
{
    if (items == null)
    {
        return;
    }

    foreach (var item in items)
    {
        this.Add(item);
    }
}</t>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900