I realize this is partially subjective, but I'm generally curious as to community opinion and have not been able to successfully find an existing question that tackles this issue.
I am in a somewhat religious debate with a fellow coworker about a particular Select statement in a L2EF query.
.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;
})
Caveats:
- This is Linq-to-Entities
- This is after the work in the DB as been performed and returned
- The input parameter
r
is anonymous
Personally, I'm of the opinion that (a) the select clause should not be altering values, it should merely project. His counter argument is that he's not altering anything, he's just making sure everything is properly initialized as a result of the DB query. Secondly, I think once he starts getting into full code blocks and return statements, it's time to define a method or even a Func<T, U>
and not do all of this inline. The complicator here is, again, the input is anonymous, so a type would need to be defined. But nevertheless, we are still debating the general point if not the specific.
So, when does a lambda expression do too much? Where do you draw the fuzzy line in the sand?