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

  • Home
  • SEARCH
  • 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 6681995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:39:16+00:00 2026-05-26T04:39:16+00:00

Could someone explain me what will happen when I execute this query I’m using

  • 0

Could someone explain me what will happen when I execute this query

I’m using (read learning) ninject and have following code

public interface IProducts
{
    IQueryable<Product> Products { get; }

   //some functions

}

I have following class “Product” which implements IProducts interface

public class Product
{
    public string Name { get; set; }
    public string Price { get; set; }

    public IQueryable<Product> Products
    {
        get
        {
            using(/*Connect to dtabase*/)
            {
                var products = from p in db.Products
                               select p;
            }
        }
    }
}

Now I have added

ninjectKernel.Bind<IProducts>().To<Product>();

I wonder what will happen if I have added another Linq query like where product.Name == Something

For example

public class ProductController : Controller
{
    private IProducs repository;

    public ProductController(IProducts products)
    {
         repository = products;
    }

    public ViewResult Find(string productName)
    {
          var product = from p in repository
                         where p.Name == productName
                         select p;
     }
}

Far as I know Linq query will execute only when I loop trough data so I wonder if these two Linq queries will merge into one.

For example

from p in db.Products
where p.Name == Something
select p;

Could someone confirm me if I got it right

  • 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-26T04:39:17+00:00Added an answer on May 26, 2026 at 4:39 am

    The compiler will effectively transform your declarative LINQ statements into method calls. (I say effectively because it’s really down to compiler internals whether method translation actually takes place or whether it ‘shortcuts’ straight to IL – this is not important for us to know in this context.)

    I.e. :-

    from p in db.Products
        select p;
    

    represents

    db.Products.Select(p => p);
    

    and

    from p in repository.Products    // .Products is missing in your code
        where p.Name == productName
        select p
    

    represents

    repository.Products.Where(p => p.Name == productName);
    

    Now, since execution is deferred, when we enumerate our final value (‘loop through data’), the following will effectively be executed:-

    db.Products.Select(x => x).Where(p => p.Name == productName);
    

    It is then down to the specific implementation of IQueryable<T> (db.Products) to translate this to whatever is appropriate. In the case of the Linq2SQL provider, this will be something like:-

    SELECT
        P.Name, P.Foo, P.Bar, ...
    FROM
        Product P
    WHERE
        P.Name = "the name you specify"
    

    So you see, due to deferred execution, the translation to a single query against the database is done for you. You don’t have to take any special action to make this happen.

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

Sidebar

Related Questions

Could someone please explain why following program will output 4,6 instead of 4,4. MainProgram()
Could someone explain why this works in C#.NET 2.0: Nullable<DateTime> foo; if (true) foo
Could someone explain why both tests using the latest versions of Moq and Rhino.Mocks
Could someone explain this (strange) behavior? Why is the length in the first example
Could someone explain to me what this portion of code means? repeat scroll 0
I'm rather new to these could someone explain the significance (of the following code)
Could someone explain to me why this is fail. Trying to get the opacity
Could someone explain to me how the following code works? I've spent a bit
Could someone explain the best way to achieve the following, I think it's a
I found this in a code I am currently studying, could someone explain it

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.