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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:59:06+00:00 2026-05-20T11:59:06+00:00

I am new to LINQ to SQL, hence this question. By default if I

  • 0

I am new to LINQ to SQL, hence this question.

By default if I do a query for a row, does LINQ to SQL fetch all the foriegn key rows?

eg:

let us say I have 1->N relationship will 3 tables

Branch -N> Departments -N> Employees
If I query a brand row

Branch b = (
    from b in brachDataContext.Branches 
    where b.id = id 
    select b).ToList();

Does this fetch all the departments related to the branch row and the employees related to these departments?

If so, wont that be a huge object. each branch might have 10 departments and each department might have 1000 employees, and we might not need all the records.

  • 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-20T11:59:07+00:00Added an answer on May 20, 2026 at 11:59 am

    Linq 2 SQL uses deferred execution by default, which means that your Departments will be fetched if you enumerate over that collection.

    However, you can control whether they should be included in the initial query by setting the context.LoadOptions property like so

    DataLoadOptions dlo = new DataLoadOptions();
    dlo.LoadWith<Branch>(b => b.Departments);
    context.LoadOptions = dlo;
    ... query ...
    

    Check this post out for more info on deferred execution.

    And also read up on the difference between IEnumerable and IQuerable and their behaviors. It is the key to understanding all Linq providers.

    As a heads up, my experience is that Linq 2 Sql works for smaller projects and rapid development etc. If you have anything else in mind, consider moving to Entity Framework or NHibernate for a more feature complete experience.

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

Sidebar

Related Questions

I'm familiar with .NET and with SQL. Now I'm looking at the new LINQ
As far as I can understand, when I new up a Linq to SQL
How do I do this in linq? var p = new pmaker(); foreach (var
This question is a follow on to link text hence the revisited in the
I go in and add a new linq to sql classes in Visual Studio
I am using LINQ To SQL and calling stored procedures to insert the new
A simple linq to SQL query Might return a product object. Obiously I could
i have generated a Linq to Sql class which looks like this. so i
I am completely new to LINQ in C#/.NET. I understand that I could use
I am new with Linq and I would like to sort some data that

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.