c# - WCF Data Services Client: How to select matching entities based on a provided T generic type and a Func? -


i'm using wcf data services/odata client library, , if target northwind sample odata store @ http://services.odata.org/northwind/northwind.svc/ , following instruction can retrieve products have quantity bigger 50:

var r = context.products.where(w=> w.unitsinstock > 50) 

my question is, suppose want have generic class must perform operation, instead of hardcoding entity retrieve (products in case) , condition on same entity (unitsinstock > 50), want supply entity object/name , condition func. have following class, imaginary getentitytype function infere entity supplied t, unfortunatelly getentitytype not exist , haven't found how accomplish same task:

public class odatatesting<t> {     ...     public iqueryable<t> returnitem(func<t, bool> selector)     {         return context.getentitytype<t>().where(w=> selector(w));     }     ... } 

update:

i've found createquery method, can used follows:

return context.createquery<t>("products").where(w=> selector(w)); 

but...
1. can't find way string entity name associated data type. there way programatically t?
2. uri generator seems have dificulties when functions used filter entities, i'll have investigate further alternatives. sugestions welcome

update 2: entity string name can retrieved using reflection:

string s = ((global::system.data.services.common.entitysetattribute)(typeof(product).getcustomattributes(typeof(global::system.data.services.common.entitysetattribute), true)[0])).entityset; 

if there more recomnended way it, please share.

i'm still looking way dinamically provide condition retrieve entities service.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -