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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:27:29+00:00 2026-05-23T09:27:29+00:00

How would I translate this into LINQ? Say I have A parent table (Say,

  • 0

How would I translate this into LINQ?

Say I have A parent table (Say, customers), and child (addresses).
I want to return all of the Parents who have addresses in California, and just the california address. (but I want to do it in LINQ and get an object graph of Entity objects)

Here’s the old fashioned way:


SELECT c.blah, a.blah
FROM Customer c
INNER JOIN Address a on c.CustomerId = a.CustomerId
where a.State = 'CA'

The problem I’m having with LINQ is that i need an object graph of concrete Entity types (and it can’t be lazy loaded.

Here’s what I’ve tried so far:

Edit: added context instantiation as requested


// this one doesn't filter the addresses -- I get the right customers, but I get all of their addresses, and not just the CA address object.

var ctx = new CustomersContext() // dbContext -- using EF 4.1 

from c in ctx.Customer.Include(c => c.Addresses)
where c.Addresses.Any(a => a.State == "CA")
select c

// this one seems to work, but the Addresses collection on Customers is always null
var ctx = new CustomersContext() // dbContext -- using EF 4.1 
from c in ctx.Customer.Include(c => c.Addresses)
from a in c.Addresses
where a.State == "CA"
select c;

Any ideas?

  • 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-23T09:27:29+00:00Added an answer on May 23, 2026 at 9:27 am

    Based on the code above, it appears that you already have a rehydrated collection of Customer objects in the Customer variable.

    You will need to call the Include function when you fill your Customer collection above. This way, the framework will rehydrate the included objects at the time of retrieval from your data context.

    The actual query code appears good though.

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

Sidebar

Related Questions

How would you translate this xcopy command into Robocopy: xcopy *.* C:\DestinationFolder\ Keeping in
How do i do translate this linq code into sql? if (storeId > 1)
I want to use XMPP to push data to my client which would translate
I've got some code which I would like to translate into Opengl ES. I'm
Would be possible to extend this kind of layout so that I can have
I can't seem to translate this to LINQ: select stuff FROM history INNER JOIN
I have a possibly large rooted tree structure that I want to transform into
In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column)
I'm having trouble getting LINQ to translate something into the query I need. In
I have this piece of code where Customers is IQueryable<Customer> Customers = Customers.Where (

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.