LINQ to SQL: Reuse lambda expression

后端 未结 2 695
一生所求
一生所求 2021-02-08 12:38

I stumbled over some strange LINQ to SQL behaviour - can anybody shed some light on this?

I want to define a lambda expression and use it in my LINQ statement. The follo

2条回答
  •  面向向阳花
    2021-02-08 12:43

    Does Table1 refer to the same namespace? In the first example you're querying against the Table1 objects that are directly under dataContext, in the second example you're querying against the Table1 objects that is a property of the Table2 objects, and in the last example you're using a anonymous function which fix the issue.

    I would look up the type of the Table1 objects that is a property of a Table2 object and compare it to a Table1 object that is connected directly to the dataContext. My guess is that they differ and your lambda expression is using the type of the object that is connected to the dataContext.

提交回复
热议问题