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 712223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:49:28+00:00 2026-05-14T04:49:28+00:00

I was wondering about the performance difference between these two scenarios and what could

  • 0

I was wondering about the performance difference between these two scenarios and what could the disadvantages be over each other?

First scenario :

public class Helper //returns IQueryable
{
   public IQueryable<Customer> CurrentCustomer
   {
      get{return new DataContext().Where(t=>t.CustomerId == 1);
   }
}

public class SomeClass
{
    public void Main()
    {
       Console.WriteLine(new Helper().CurrentCustomer.First().Name;
    }
}

The second scenario :

public class Helper //returns Enumerated result
{
   public Customer CurrentCustomer
   {
      get{return new DataContext().First(t=>t.CustomerId == 1);
   }
}

public class SomeClass
{
    public void Main()
    {
       Console.WriteLine(new Helper().CurrentCustomer.Name;
    }
}

Thanks in advance.

  • 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-05-14T04:49:28+00:00Added an answer on May 14, 2026 at 4:49 am

    Well, the main difference that I can see is when the query is executed and what else you can do with the query.

    For example, suppose your Customer object has some large fields. Using the second approach, you will always fetch them. Using the first approach you could write:

    string name = helper.CurrentCustomer.Select(x => x.Name).First();
    

    That would then only need to query the single field in the database. In terms of timing, the query will only be executed when you actually request the data (which is how it’s able to wait until after you’ve used Select to work out what to put in the query in the above case). That has pros and cons – it can make it harder to reason about, but it can save some work too. In terms of the “reasoning about” side, you know that once you’ve got a customer, you’ve got an object you can just work with. If you use the same queryable twice though, you need to know whether your LINQ query provider is going to cache the result… if you write:

    IQueryable<Customer> currentCustomerQuery = helper.CurrentCustomer;
    Customer x = currentCustomerQuery.First();
    Customer y = currentCustomerQuery.First();
    

    will that issue the query once or twice? I suspect it very much depends on the provider, but I wouldn’t like to make any guesses about specific ones.

    The other thing to think about is how easy it is to use the API you’re building. Personally I’d normally find it easier to use an API which gives me the data I want rather than a query I can fetch that data from. On the other hand, it is slightly less flexible.

    One option would be to allow both – have a GetCurrentCustomerQuery() and a GetCurrentCustomer() method. (I probably wouldn’t make them properties myself, but that’s merely a matter of personal preference.) That way you can get the flexibility you want when you really need it, but have a simple way of just getting the current customer as an object.

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

Sidebar

Related Questions

I am wondering about performance difference between stored procedure and scalar-valued function. For now
I was wondering about performance difference between : this.BTN_LogIN.Click += new EventHandler(BTN_LogIN_Click); vs <asp:Button
I'm wondering about the performance differences between imports and inherits in a .net app.
I'm wondering about if there is a difference (in performance) when I use: User
Just wondering about the performance impact of copying very large php variables. For example
I am wondering about the performance of connecting to the database. Is it okey
I am wondering about the performance of this index: I have an Invalid varchar(1)
I have been wondering about the performance of regular expression implementations lately, and have
I was wondering if there were any performance implications between using TPL TaskFactory.FromAsync and
I checked and could find numerous posts about performance of float vs double (

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.