Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104741

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.

Upvotes: 3

Views: 684

Answers (2)

Akash Kava
Akash Kava

Reputation: 39916

Instead, I would suggest to use Text Template of EF generator to create RIA Services operations for every entity. And use a pattern of name like how RIA Services uses "Get" <Type> Query, and other methods.

Upvotes: 1

Jehof
Jehof

Reputation: 35544

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.

Upvotes: 2

Related Questions