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

本文是小编为大家收集整理的关于Linq to Entity Query .Expand的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我得到了以下表格 TableA,TableB,TableC,TableD,TableE,它们具有外国密钥关系 fk_ab(一对一),fk_bc(一对一),fk_cd(一对数),fk_de(一对一),并基于这些外国keys 现在,我想查询tablea,并从table,table and table whose loaded column等于系统中获取记录.我的查询就像以下

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

上面的查询正常工作.我希望来自Tableed和table hoose的记录加载值等于系统,但是上述查询返回与table和table的所有记录相关的记录,这些记录与满足的tablea记录A.LoadedBovaly ="系统"此条件未在子表中选中此条件.

任何人都可以告诉我如何也过滤子表.

推荐答案

当前ODATA仅支持顶级的过滤器.因此,在上面的示例中,它只能过滤the Tablea的行.内部扩展将包括所有资助行,始终将无法过滤这些行. 您也许可以通过其他查询(带有正确的过滤器)分别询问Exanded实体,并可能使用批次将所有查询分组为一个请求.但这取决于您需要发送的实际查询.

本文地址:https://www.itbaoku.cn/post/1557119.html

问题描述

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;

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.

推荐答案

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.