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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:30:21+00:00 2026-06-18T09:30:21+00:00

I have a situation where I’d like to eager load the organization property of

  • 0

I have a situation where I’d like to eager load the organization property of a user being retrieved from the DB using LINQ-to-SQL (because of my using here attempts to get the property later fail because the context’s connection is closed). The problem is that sometimes the user does not have an organization. In that case FetchUserByName returns null. Not what I want at all. Is there a way to get this to work the way I want, which is to return an instance of user whether they have an associated organization or not?

    private static void EagerLoad(DataContext ctx)
    {
        var loadOpt = new DataLoadOptions();
        loadOpt.LoadWith<User>(u => u.Organization);
        ctx.LoadOptions = loadOpt;
    }

    public User FetchUserByName(string username)
    {
        User user = null;
        using (var ctx = contextManager.GetSingleDataContext())
        {
            EagerLoad(ctx);
            user = ctx.GetTable<User>().SingleOrDefault(u => u.UserName == username && u.IsActive);
        }

        return user;
    }
  • 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-18T09:30:22+00:00Added an answer on June 18, 2026 at 9:30 am

    Documenting what the fix was for others who may run into this.

    LoadWith actually determines whether to use an INNER JOIN or an OUTER LEFT JOIN in the SQL created by LINQ-to-SQL by looking whether the foreign key in the data model class is nullable in the database. If it is nullable it uses the outer join.

        [Column]
        public int OrganizationId { get; set; } /*** Here is The Problem ***/
    
        private EntityRef<Organization> _organization;
    
        [Association(OtherKey = "OrganizationId", Storage = "_organization", ThisKey = "OrganizationId", IsForeignKey = true)]
        public Organization Organization
        {
            get
            {
                return this._organization.Entity;
            }
        }
    

    Changed the one line to:

    public? int OrganizationId { get; set; }
    

    And then everything worked as expected.

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

Sidebar

Related Questions

I have situation like this: user submits form with action='/pay' in '/pay' I have
I have situation where I have to call method of interface using reflection, like
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation in which I read a record from a database. And if
I have situation where a user can manipulate a large set of data (presented
I have situation, when user prepare some data in ASP.NET application, it save them
I have situation where a 3rd party open source product I am using is
We are using Twitter Bootstrap for my application. I have situation where I have
I have a situation like below in which I have some problem in freeing
I have a situation to choose between parsing XML documents in Oracle PL/SQL and

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.