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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:31:41+00:00 2026-06-11T01:31:41+00:00

Using entity framwork with lazy loading – Have the following question on loading related

  • 0

Using entity framwork with lazy loading – Have the following question on loading related entities when the entities
are null.

Say I have two tables employee and employeedetails. Assume in the above case not all employee entries have an entry in the employeedetails table.
If I want to look up a list of Employees

(from e in objectcontext.employees                                  
                              select new EmployeeEntity
                              {
                                  EmpID= e.EmployeeID,
                                  FirstName = e.FirstName,
                                  Address = e.employeedetails.Address
                              }).ToList();

EmployeeEntity is the data class into which we stuff the results.

The above code breaks if even one employee in the returned list
does not have a entry in table employeedetails. This is obvious since e.employeedetails will be null for those customers who do not have a details entry

What is the best way to rewrite the above query?

Would something like this be acceptable ?

(from e in objectcontext.employees                                  
                              select new EmployeeEntity
                              {
                                  EmpID= e.EmployeeID,
                                  FirstName = e.FirstName,
     Address = e.employeedetails  == null ? "" :    e.employeedetails.Address,
                              }).ToList();

I am not clear on the efficiency of this above query – Would this statment do the null check at DB level?

Should I instead do an explicit include like

objectcontext.include("employeedetails")...

And then loop through the results to check for null?

  • 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-11T01:31:43+00:00Added an answer on June 11, 2026 at 1:31 am

    Yes, this statement would indeed perform a null check in the SQL query that is generated. Most likely, it will simply be a NVL or COALESCE.

    That’s the way you should be doing it.

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

Sidebar

Related Questions

I am using Entity Framework and I have two tables, a contact relationship table
Using Entity Framework 4.1 I have the following tables I'm using with Entity Framework
In Entity Framework 4, what is the difference between Lazy Loading, and using Load()
Let's say I have a Student entity like this implemented using the Play Framework's
I need advice on using stored procedures with Entity Framwork 4.x to return data
Using Entity Framework 4.1 code first and POCO entities in MVC3; I would like
I am using Entity Framework 4.1 with POCOs and DbContext, no proxies no lazy
I am using Entity Framework CodeFirst where I have used Parent Child relations using
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a
I am using Entity Framework through a Repositories pattern and have a significant 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.