Linq to Entity Query .Expand

橙三吉。 提交于 2019-12-11 10:12:43

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9418745/linq-to-entity-query-expand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!