Linq-to-SQL EntitySet Is Not IQueryable — Any Workarounds?

后端 未结 2 2154
情话喂你
情话喂你 2021-02-15 15:14

When you query an EntitySet property on a model object in Linq-to-SQL, it returns all rows from the entityset and does any further querying client-side.

This is confir

2条回答
  •  别那么骄傲
    2021-02-15 15:54

    I had a similar problem: How can I make this SelectMany use a join. After messing with LINQPad for a good amount of time I found a decent workaround. The key is to push the EntitySet you are looking at inside a SelectMany, Select, Where, etc. Once it's inside that it becomes an Expression and then the provider can turn it into a proper query.

    Using your example try this:

    var query = from c in Children
                where c == myChild
                from p in c.Parents
                where p.Age > 35
                select p;
    

    I'm not able to 100% verify this query as I don't know the rest of your model. But the first two lines of the query cause the rest of it to become an Expression that the provider turns into a join. This does work with my own example that is on the question linked to above.

提交回复
热议问题