Search code examples
entity-frameworkgenericswcf-ria-services

WCF RIA Generic Server-side query?


Is it possible to have a generic server-side query like the following?

public IQueryable<TContact> GetContactsOfType<TContact>()
  where TContact : Contact
{
  return ObjectContext.Contacts.OfType<TContact>();
}

I want RIA to recognize and regenerate for me this query at the client project.

Note: Contact is an abstract class that has some subclasses. I'm using Entity-Framework generated EntityObjects.

The error I get when I'm trying compile: Type 'TContact' is not a valid entity type. Entity types must have a default constructor.


Solution

  • By default WCF RIA Services does not expose generic domain service methods for the client to call. RIA is strongly-typed to make it easier to reason about the behavior.

    But there seems to be a workaround with defining your on DomainOperationEntry and a custom DomainServiceDescriptionProvider. Colin Blair posted an answer here. That seems to match what you are expecting.

    Update: I tried what you want im my silverlight project and defined a generic query method on my domain service. The project compiles successfully but the generic parameter is ommited on the client side.