In my previous post I mentioned how to specify an association between POCO objects in RIA Services. In that post I did not mention that you will get an error as soon as you try to do some operations on associated objects. The error might look like this: "EntitySet of type 'Option' does not support the 'Add' operation".

There are two ways to solve the issue. First of all, it is necessary to decide what type of association you have. In case of composition you just need to use a new CompositionAttribute (read more in Mathew Charles' post):

// "Master" domain entity class.

public class Parameter {
    public long Id { get; set; }

    public string Name { get; set; }

    [Association("Parameter_Options", "Id", "ParameterId")]
    public List<Option> Options { get; set; }

// "Details" domain entity class.

public class Option {
    public long Id { get; set; }

    public long ParameterId { get; set; }

    public string Name { get; set; }

If you do not have the compositional association, you have to specify operations in the corresponding domain service.

public class ParametersDomainService : DomainService
    public IEnumerable<Parameter> GetParameters() { ... }
    public void AddParameter(Parameter parameterWithOptions) { ... }
    public void UpdateParameter(Parameter parameterWithOptions) { ... }
    public void DeleteParameter(Parameter parameterWithOptions) { ... }

    public void AddOption(Option option) { ... }
    public void UpdateOption(Option option) { ... }
    public void DeleteOption(Option option) { ... }

In the AddParameter, UpdateParameter and DeleteParameter methods you will receive the parameter object with associated options. It is up to you whether to perform operations on option objects together with operations on parameters or to do it in the corresponding methods. Note that AddOption, UpdateOption and DeleteOption should exist, but they could remain empty.


Cleyton wrote 2/9/2011 at 12:34 PM Hi,

thanks for this post about composition in Ria Services.

I was wondering if you have any source code that goes with the article so that I can download it?


Yauhen wrote 2/9/2011 at 1:46 PM Hi Cleyton,

No, I don't have any source code prepared for this article. The code you can see I adopted from my pet project.

You can find some code in Mathew's article I referenced above:

Hope it will help.
rob wrote 11/5/2011 at 10:12 PM Excellent article. Exactly the information I was looking for.