Insert → <Dear Uncle Kevin
>
dsReceipts.RcvDtl.Sum(x => x.ThisTranQty)
Well one area of confusion is there are 2 forms of lambda expression.
You have expressions, and statements.
What you have there, is an expression lambda.
The code above, in English says:
Please (be nice) return the sum of the field ThisTranQty from the RcvDtl table in the dsReceipts (TableSet or DataSet).
This part, is not lambda at all: dsReceipts.RcvDtl.Sum
.
It is traditional Object Oriented Programming notation, so you have this:
decimal IamAvariableOffScreen = [Object][ChildObject][ExtensionMethodOnObjectByType]()
The next part is where the lambda is:
x => x.ThisTranQty
You can tell by the => operator.
This part defines that we’ll be working on x, and we will use the lambda operator => to define an “anonymous” “inline” “function” that returns the ThisTranQty field from x TO the Sum (Extension) Function.
The variable x will take on the value of what is fed in to it. In this case, it represents the RcvDtl table, as that is what we are running our extension method on.
We don’t see the magic of Sum here, but it takes a number of objects and does it’s thing. We are just using lambda to provide it the data.
I’ll explain further later, this is hard to get right and explain well.
This goes back to delegates, Actions, Funcs etc. I guess I will need to explain extension methods as well.
I will try to show how the cake is made eventually, but it’s a bit of a mouth full.
Fun fact, LINQ, is pretty much all extension methods, all the way down.