Search code examples
asp.netsilverlightwcf-ria-servicesdomainservices

Unable to retrieve single entity


I'm trying to retrieve a single entity by its ID in the DomainService.

However the type of that entity is not generated in the client. Here is my query:

public Contact GetContact(int contactId)
{
  return DbContext.Contacts
    .Include(c => c.Phones)
    .Include(c => c.Addresses)
    .SingleOrDefault(c => c.ContactId == contactId);
}

The Phone entity isn't generated on the client.

I tried decorating this method with [Query], but then I get the following compile-time exception:

Query operation 'GetContact' cannot be marked composable since its return type 'Models.Contact' does not implement IEnumerable of T.

Is there any way to create a WCF RIA query that returns a single entity by ID?


Solution

  • Setting the IsComposable property will allow it to build. But as in our discussion, I don't know why your Phone and Address entities are not being generated.

    [Query(IsComposable=false)]
    public Contact GetContact(int contactId)
    {
      return DbContext.Contacts
        .Include(c => c.Phones)
        .Include(c => c.Addresses)
        .SingleOrDefault(c => c.ContactId == contactId);
    }