Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:31:46+00:00 2026-06-02T03:31:46+00:00

I’m writing a LightSwitch application and i could do with some advice. I wanted

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:31:47+00:00Added an answer on June 2, 2026 at 3:31 am

    Question 1:

    partial void OpenPositions_Compute(ref int result)
    {
        result = this.DataWorkspace.ApplicationData.Positions
            .Count(p => p.IsPositionOpen && position.Client.Id == this.Id);
    }
    

    Question 2:

    It depends on usage. In this case, the biggest advantage is concise code, since you can use LINQ without having to re-implement the counting functionality. Performance can sometimes be increased. Using LINQ as an example again, LINQ uses deferred execution to prevent executing code until it is needed.

    Usually, the lambda is not the solution, rather, it is part of the solution. Using LINQ is generally the solution for thing like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing my first silverlight application. I need to deliver some bitmap that the customer
Writing documentation in html requires some code examples. What to do with characters that
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
Writing my first C# application...never touched the language before and not much of a
Writing a client application that sends images to a server via a webservice. As
While writing some C code, I decided to compile it to assembly and read
Writing some drag&drop code, I'd like to cancel the click events in my mouseup
Writing some classes for a Framework extension, and I have the following code: public
Writing a function to generate and push some random data inside of the unknown
Writing some regex to help process street addresses. However, I'm unsure if regex is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.