Domain Service method not compiling; claims "Return types must be an entity ..."

Duncan Bayne picture Duncan Bayne · Apr 9, 2010 · Viewed 8.7k times · Source

I have a WCF RIA Domain Service that contains a method I'd like to invoke when the user clicks a button:

[Invoke]
public MyEntity PerformAnalysis(int someId)
{
    return new MyEntity();
}

However, when I try to compile I'm given the following error:

Operation named 'PerformAnalysis' does not conform to the required signature. 
Return types must be an entity, collection of entities, or one of the 
predefined serializable types.  

The thing is, as far as I can tell, MyEntity is an entity:

[Serializable]
public class MyEntity: EntityObject, IMyEntity
{
    [Key]
    [DataMember]
    [Editable(false)]
    public int DummyKey { get; set; }

    [DataMember]
    [Editable(false)]
    public IEnumerable<SomeOtherEntity> Children { get; set; }
}

I figure I'm missing something simple here. Could someone please tell me how I can create an invokable method that returns a single MyEntity object?

Answer

bleepzter picture bleepzter · Sep 14, 2011

The code that you have here:

[Invoke]
public MyEntity PerformAnalysis(int someId)
{
    return new MyEntity();
}

is fine, but you also need a IEnumerable to make this work:

public IEnumerable<MyEntity> GetMyEntities()
{
    throw new NotImplementedException();
}

What that means is that for WCF RIA service to return custom types it needs to have at least one method for that custom type that returns an IEnumerable of that type.