This is is returning a boolean based on whether or not there are some matching IDs.
from t in getAll
select new Result
{
...
bool DetailsAvailable =
(db.SaveTrackings.Where(s => s.BundleID == t.bundleID
&& s.UserID == t.userID)
.Count() > 0) ? true : false;
}
This is what I think understand: .Where()
is returning all the entries with the matching IDs and then the .Count()
is just seeing how many are there. I only feel like I half understand what we need s
for.
I know what to expect from this code since it's been in use I just don't understand how it works and some of the documentation from MSDN is using some terminology that is confusing me.
All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x."
So how am I suppose to understand what my code means based on this, .Where(s
"goes to" s.BundleID == t.BundleID
...) so what's happening here? What does "goes to" mean? Is it comparing every ID in s
to everyone one available in t
? How do I understand why it's called "goes to" and what exactly is happening?
And then it gets more confusing...
The => operator has the same precedence as assignment (=) and is right-associative.
Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as Where.
When you use method-based syntax to call the Where method in the Enumerable class (as you do in LINQ to Objects and LINQ to XML) the parameter is a delegate type System.Func. A lambda expression is the most convenient way to create that delegate.
What is a delegate type System.Func<T, TResult>
and how is it created with this "goes to" operator?
I can't just use code because I know that it's working, I need to understand how/why.