简体   繁体   English

WCF 服务(实体)¨linq quert select db table 通过参数 webget 可能吗?

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

i wanted to ask if it possible to select an entity database table through a webget parameter ?我想问一下是否可以通过webget参数选择实体数据库表? 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.您无法序列化IQueryable<T> ,因此您无法通过 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.我们正在使用Automapper将我们的域实体映射到 DTO。

If you are hardcore, take a look at this discussion about serializing func .如果您是铁杆,请查看有关序列化 func 的讨论。

It could however be possible to serialize TestTable[] .然而,可以序列化TestTable[] TestTable must be a known class that can be instantiated (ie not abstract, not an interface). TestTable 必须是可以实例化的已知类(即不是抽象的,不是接口)。 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. .ToArray()执行您的查询,因此现在您发送的是实际数据,而不是抽象语法树。

--Edit-- - 编辑 -

Sorry, I was totaly wrong about the impossibility of sending IQueryable over the wire.抱歉,我完全错误地认为不可能通过网络发送 IQueryable。 I totally missed that we are talking about an OData service here.我完全没有注意到我们在这里谈论的是 OData 服务。 I was thinking about SOAP services all the time.我一直在考虑 SOAP 服务。 Thanks Rytmis for clearing that up.感谢 Rytmis 解决了这个问题。 Googling with the correct search terms also turned up this discussion: Expose IQueryable Over WCF Service谷歌搜索正确的搜索词也出现了这个讨论: Expose IQueryable Over WCF Service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM