i wanted to ask if it possible to select an entity database table through a webget parameter ? here is what it might look like :
[WebGet]
public IQueryable<TestTable> GetAllCallers(string select, string **table**)
{
//testCDREntities context = this.CurrentDataSource;
var Callers = from d in this.CurrentDataSource.**table**
select d ;
return Callers;
}
ofcourse this doesn't work but is there a way to let this work ? I hope somebody can help me with this :)
This is impossible. You can't serialize IQueryable<T>
, therefore you can't send it trough WCF.
The usual way is to pack the properties you need into a serializable Data Transfer Object. We are using Automapper to map our domain entities to DTOs.
If you are hardcore, take a look at this discussion about serializing func .
It could however be possible to serialize TestTable[]
. TestTable must be a known class that can be instantiated (ie not abstract, not an interface). Also all properties used in the datacontract must be serializable.
return Callers.ToArray();
.ToArray()
executes your query, so now you are sending the actual data, not an abstract syntax tree.
--Edit--
Sorry, I was totaly wrong about the impossibility of sending IQueryable over the wire. I totally missed that we are talking about an OData service here. I was thinking about SOAP services all the time. Thanks Rytmis for clearing that up. Googling with the correct search terms also turned up this discussion: Expose IQueryable Over WCF Service
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.