Search code examples
silverlightwcf-ria-services

SubmitChanges not working with WCF RIA and POCO Child Objects


I have a Parent POCO class ParentItem with a List<ChildItem> inside it and i have set the correct AssociationAttribute. But when i am trying to add a ChildItem to the ParentItem using ParentItem.ChildItems.Add(childItem), the domainContext's HasChanges is true, but DomainContext.SubmitChanges is not working.

I checked the HasError property and there are no errors, but its not calling the Insert or Update operations. It works fine if i change any other property of the ParentItem.

I am using Silverlight 5.0, WCF RIA SP1 and EF 4.0, and i am not sure what i am doing wrong!

UPDATE

I replaced the SubmitChanges with an Invoke method and found out that at the server side i am not getting the children. The children count is zero. Does that means my association is wrong?

This is my structure

public class ParentItem
{
    [Key]
    public int ParentId{get;set;}

    [Include]
    [Association("ChildrentItems", "ParentId", "ParentId")]
    public List<ChildItem> Children{get;set;}
}

public class ChildItem
{
    [Key]
    public int ChildItemId{get;set;}
    public int ParentId{get;set;}
    public string Code {get;set;}
}

Thanks.


Solution

  • By adding the [Composition] attribute, you are instructing WCF RIA to track changes to the collection within Silverlight and publish the deltas to the server on DomainContext.SubmitChanges.

    public class ParentItem
    {
        [Key]
        public int ParentId{get;set;}
    
        [Include]
        [Association("ChildrentItems", "ParentId", "ParentId")]
        [Composition]
        public List<ChildItem> Children{get;set;}
    }