Iām writing a LightSwitch application and i could do with some advice.
I wanted to calculate the total number of child objects related to the parent object that fulfil the criteria of being true and related to the Client.
partial void OpenPositions_Compute(ref int result)
{
foreach (Position position in this.DataWorkspace.ApplicationData.Positions)
{
if (position.IsPositionOpen && position.Client.Id == this.Id)
{
result++;
}
}
}
I did experiment with calculating the number of Positions a client had without using a foreach loop and i came up with this:
partial void TotalPositons_Compute(ref int result)
{
result += this.Position.Count();
}
Question 1: Is it possible to write snippet 1 in a better/more efficient way? Perhaps as a lambda equation? (or similar to the second code snippet)
Question2: What benefits would a lambda equation give other than readability of code?