Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I Perform a 'Distinct' with a WCF Data Service (OData) Query?

I really need to be able to perform a 'DISTINCT' on a WCF Data Service query.

From what I can tell, such a function doesn't exist. I know that I can use the Distinct extension method in the Linq query on the client, but it still hydrates the full result set (which isn't what I want in this particular case).

Any ideas?

like image 941
Jordan Parmer Avatar asked Oct 05 '10 20:10

Jordan Parmer


2 Answers

Not built in. It's also not currently part of the OData protocol at all (no aggregation is other than count, which we would definitely need to even consider it). The recommended approach is to retrieve all data and do set operations on the client (yuck!).

That said, you'd have to somehow extend WCF Data Services on both the client and server to provide this functionality (I'm not familiar enough with it to point you to the right hooks).

You could always go with providing a WebMethod (this is just WCF by the way) to do this work, but I would imagine that's not how you intend to use Data Services.

like image 185
Marc Avatar answered Oct 05 '22 01:10

Marc


I'd recommend using a WCF Data Service, Service Operation - http://msdn.microsoft.com/en-us/library/cc668788.aspx, as a better solution (over a webmethod). Service Operations are a great way to encapsulate query functionality not enabled by the OData query syntax.

like image 21
Don Demsak Avatar answered Oct 04 '22 23:10

Don Demsak