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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:23:05+00:00 2026-06-16T05:23:05+00:00

I’ve taken control of some entity framework code and am looking to refactor it.

  • 0

I’ve taken control of some entity framework code and am looking to refactor it. Before I do, I’d like to check my thoughts are correct and I’m not missing the entity-framework way of doing things.

Example 1 – Subquery vs Join

Here we have a one-to-many between As and Bs. Apart from the code below being hard to read, is it also inefficient?

from a in dataContext.As
where ((from b in dataContext.Bs
        where b.Text.StartsWith(searchText)
        select b.AId).Distinct()).Contains(a.Id)
select a

Would it be better, for example, to use the join and do something like this?

from a in dataContext.As
where a.Bs.Any(b => b.Text.StartsWith(searchText))
select a

Example 2 – Explicit Joins vs Navigation

Here we have a one-to-many between As and Bs and a one-to-many between Bs and Cs.

from a in dataContext.As
join b in dataContext.Bs on b.AId equals a.Id
join c in dataContext.Cs on c.BId equals b.Id
where c.SomeValue equals searchValue
select a

Is there a good reason to use explicit joins rather than navigating through the data model? For example:

from a in dataContext.As
where a.Bs.Any(b => b.Cs.Any(c => c.SomeValue == searchValue)
select a
  • 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-16T05:23:06+00:00Added an answer on June 16, 2026 at 5:23 am

    Sometimes it is necessary to use the join-style and subqueries to get control over certain aspects of a LINQ 2 SQL query. This is not the case here. The “navigation” style is strictly preferable. Sometimes, it even comes with performance benefits because LINQ to SQL used smarter SQL patterns.

    I don’t just want to answer with “you’re right” so let me say that I have a lot of experience with LINQ to SQL. I’m using it on two bigger projects where performance is critical and almost every generated SQL statement is perf-tested by me. So this answer bears some authority and isn’t just a random internet opinion.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.