I understand that this is partially subjective, but I'm generally interested in learning from the community and have not been able to successfully find an existing issue that solves this problem.
I am participating in several religious debates with a colleague over a particular Select statement in an L2EF request.
.Select(r => { r.foo.Bar = r.bar; r.foo.Bar.BarType = r.Alpha; if (r.barAddress != null) { r.foo.Bar.Address = r.barAddress; r.foo.Bar.Address.State = r.BarState; } if (r.baz != null) { r.foo.Bar.Baz = r.baz; if (r.bazAddress != null) { r.foo.Bar.Baz.Address = r.bazAddress; r.foo.Bar.Baz.Address.State = r.BazState; } } return r.foo; })
Cautions:
- This is Linq-to-Entities
- This is after working in the database, as was done and returned
- The input parameter
r is anonymous
Personally, I believe that (a) the select clause should not change the values, it should just be projected. His counter argument is that he does not change anything, he just made sure that everything was correctly initialized as a result of the database query. Secondly, I think that as soon as it starts filling out the complete blocks of code and returns instructions, it's time to define a method or even Func<T, U> , and not do it all inline. In addition, the complicating element is again anonymous, so you must determine the type. Nevertheless, we are still discussing a general question, if not a specific one.
So, when does a lambda expression do too much? Where do you draw a fuzzy line in the sand?
c # lambda linq
Anthony pegram
source share