4

I'd need to be able to combine 2 lambda expressions into 1:

This would serve me to create an extension to the type-safe includes (for EF).

Now you can do:

context.House
.Include(x => x.Doors.Doorknobs)

I'd like to be able to split up the above statement into different methods.

something like IncludeDoorKnobs(query, expressionFromRoot, expressionFromCurrentToChild)

Then I'd like to - Include the combined expression to the query - Include extra childs (from current) to that query - Call other similar methods, including another part of the tree.

My knowledge of Lambda's clearly comes short, and I'd really need to get into them soon, but for now, I have to resort tho SOF...

alamar
  • 18,729
  • 4
  • 64
  • 97
Bertvan
  • 4,943
  • 5
  • 40
  • 61

1 Answers1

1

With LINQ-to-SQL this would be trivial; you just use Expression.Invoke to tell it to use an existing sub-expression (with parameter substitution) at the given point. However, EF doesn't (or didn't last time I checked) support this.

Unfortunately, the process for combining two expressions without this is... complex; you essentially need to completely re-build the inner tree, doing manual substitution for things like parameters. I did have some code that did this, but it is far from simple (and it isn't "to hand").

But I wonder: is it really worth the complexity?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900