Linq to Entity Query .Expand [英] Linq to Entity Query .Expand

查看:59
本文介绍了Linq to Entity Query .Expand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了以下表格 TableATableBTableCTableDTableE,它们具有外键关系,例如 FK_AB(一对多),FK_BC(一对一),FK_CD(一对多),FK_DE(一对一),并具有基于这些外键的导航属性 现在,我想查询TableA并从TableA,TableD和TableE中获取记录,这些记录的Loadedby列等于System.我的查询如下所示

I got the following tables TableA, TableB, TableC, TableD, TableE and they have foreign key relations like FK_AB(one to many),FK_BC(one to one),FK_CD(One to many),FK_DE(one to one) and have the navigation properties based on these foreignkeys Now I want to query TableA and get the records from TableA, TableD and TableE whoose Loadedby column equal to System. My query is like below

var query= from A in Context.TableA.Expand(TableB/TableC/TableD).Expand(TableB/TableC/TableD/TableE)
           where A.Loadedby=="System"
           select A;

上面的查询工作正常.我希望来自TableD和TableE的记录的Loadedby值等于System,但上述查询返回来自TableD和TableE的所有与满足A.Loadedby ="System"的TableA记录相关的记录,在子表中不检查此条件.

The above query is working fine. I want the records from TableD and TableE whoose Loadedby value equal to System but the above query returning all the records from TableD and TableE which are related to TableA record satisfying A.Loadedby="System" this condition is not checked in the child tables.

谁能告诉我如何也过滤子表.

Can anyone tell me how to filter the child tables also.

推荐答案

当前OData仅支持顶级过滤器.因此,在上面的示例中,它只能过滤TableA中的行.在扩展内部,所有适当的行都将被包括在内,始终无法立即过滤掉这些行. 您可能能够通过其他查询(使用正确的过滤器)分别询问扩展实体,并可能使用批处理将所有查询分组到一个请求中.但这取决于您需要发送的实际查询.

Currently OData only supports filters on the top-level. So in the above example it can only filter rows from the TableA. Inside expansions all the approriate rows will be included, always, there's no way to filter those right now. You might be able to ask for the exanded entities separately with additional queries (with the right filter) and possibly use batch to group all the queries in one request. But that depends on the actual query you need to send.

这篇关于Linq to Entity Query .Expand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆