Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 270
Shimmy Weitzhandler Avatar asked Jul 27 '26 19:07

Shimmy Weitzhandler


2 Answers

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.

like image 106
Jehof Avatar answered Jul 30 '26 10:07

Jehof


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.

like image 43
Akash Kava Avatar answered Jul 30 '26 08:07

Akash Kava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!