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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:58:13+00:00 2026-05-12T08:58:13+00:00

I have following LINQ to SQL query expression from msg in TblUserMessages join user

  • 0

I have following LINQ to SQL query expression

from msg in TblUserMessages 
join user in Aspnet_Users on msg.FromUserID equals user.UserId
select new {
       msg.FromUserID, 
       msg.ToUserID, 
       msg.MessageLocationID, 
       msg.MessageID, 
       user.UserName
       }

And following LINQ method expression:

TblUserMessages
.Join (
  Aspnet_Users, 
  msg => msg.FromUserID, 
  user => user.UserId, 
  (msg, user) => 
     new  
     {
        FromUserID = msg.FromUserID, 
        ToUserID = msg.ToUserID, 
        MessageLocationID = msg.MessageLocationID, 
        MessageID = msg.MessageID, 
        UserName = user.UserName
     }
)

Both of these return same result set. Which is e.g. :

82522f05-2650-466a-a430-72e6c9fb68b7
6b2a174a-8141-43d2-b3ad-5b199bcbfcae
1
1
waheed

Which one is better to use. The FIRST one or the SECOND one.

Thanks

  • 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-12T08:58:13+00:00Added an answer on May 12, 2026 at 8:58 am

    They are equivalent. They don’t just return the same result set – they compile to the same code.

    Use query expressions or dot notation for individual cases depending on readability. For joins, I find the dot notation quite cumbersome – but I use it for situations where I only have one or two clauses (usually where/select). Even with two clauses (usually where and select) I find dot notation nice if you then need to use it anyway. For example, I like:

    var query = people.Where(person => person.Age > 18)
                      .Select(person => person.Name)
                      .Skip(100)
                      .Take(10);
    

    over

    var query = (from person in people
                 where person.Age > 18
                 select person.Name)
                .Skip(100)
                .Take(10);
    

    For more complicated queries (e.g. joins) I’d probably just separate the two:

    var baseQuery = from person in people
                    where person.Age > 18
                    join company on person.CompanyId equals company.CompanyId
                    select new { person.Name, company.Name };
    
    var fullQuery = baseQuery.Skip(100)
                             .Take(10);
    

    I just find this separation makes it easier to read.

    I believe it’s really useful for developers to understand at least the basics of what query expressions do – the fact that they’re basically translations into dot notation, and that the language itself doesn’t know anything about LINQ to Objects, LINQ to SQL etc; it’s just a case of following an appropriate pattern. It’s a great bit of design, which means query expressions only affect one little bit of the language specification.

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

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can pass a StringBuilder as a char*. Have a… May 12, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer The == operator may be overridden, and if it is,… May 12, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer OK, I understand the problem now I think. I would… May 12, 2026 at 8:59 pm

Related Questions

I'm having trouble getting LINQ to translate something into the query I need. In
I have the following classes (I've trimmed the code): public class SqlWeightTrackerRepository : IWeightTrackerRepository
DBML I have the following entities in my dbml: (made up for an example)
I have an ASP.NET site that has been running perfectly for a long time,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.