WCF service (entity) ¨linq quert select db table through parameter webget possible?

121 Views Asked by At

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 :)

1

There are 1 best solutions below

3
Georg Patscheider On

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 (i.e. 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