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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:09:32+00:00 2026-05-11T12:09:32+00:00

I have a LINQ query: var result = from mt in MessageTypes join mtfmt

  • 0

I have a LINQ query:

var result = from mt in MessageTypes             join mtfmt in MessageTypeField_MessageTypes                 on new { MessageTypeID = mt.ID, MessageTypeFieldID = messageTypeFieldId } equals new { MessageTypeID = mtfmt.MessageTypeID, MessageTypeFieldID = mtfmt.MessageTypeFieldID }             where (mt.StatusID == (int)status)             select mt; 

Or Lambda syntax if you prefer (the one I am using) (messageTypeFieldID is set above the var call from a param.):

var messageTypes = context.MessageTypes                 .Join(                 context.MessageTypeField_MessageTypes,                 mt =>                 new                     {                         MessageTypeID = mt.ID,                         MessageTypeFieldID = messageTypeFieldID                     },                 mtfmt =>                 new                     {                         MessageTypeID = mtfmt.MessageTypeID,                         MessageTypeFieldID = mtfmt.MessageTypeFieldID                     },                 (mt, mtfmt) =>                 new                     {                         mt = mt,                         mtfmt = mtfmt                     }                 )                 .Where(x => (x.mt.StatusID == (int)status))                 .Select(x => x.mt); 

I’ve just started learning LINQ joins and approached a situation where it is required in a new normalization (many-many) table I am setting up and I wish to return all message types each with their associated field which lives under ‘MessageTypeField_MessageType’.

My ‘MessageTypeField_MessageTypes’ table is a fairly simple normalization strategy setup like this and I should state even though MessageTypeID ‘has many’ it is unique data so it could be:

[ID | MessageTypeID | MessageTypeFieldID]  1    63      10  1    63      11  1    63      12 

Now the above code executes and returns a query I am happy with.. (performs correct INNER JOIN) but when I look at messageTypes.ToList()[0].MessageTypeField_MessageTypes for example with quick watch, where I would expect to see 1 record, I am getting an entire stack of messageTypeField_MessageType records ~17, only filtered by MessageTypeFieldID and not by MessageTypeID as well. It should filter by the message type id on each iteration and only return me just the one record. Any ideas on what I am doing wrong, or how I can achieve what I need?

Sorry for the complicated example, but I hope you guys can help!

  • 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. 2026-05-11T12:09:33+00:00Added an answer on May 11, 2026 at 12:09 pm

    If you are looking at a navigation property (i.e. some child collection of mt), then this is unrelated to your query; it sounds like you want to use AssociateWith. This largely replaces the join if you are just trying to filter the child data…

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

Sidebar

Related Questions

If you have a simple Linq query like: var result = from record in
I have this LINQ-query: // types... LinkedList<WeightedItem> itemScores = new LinkedList<WeightedItem>(); var result =
I have following query: var result = ( from role in db.Roles join user
I have a simple LINQ query on ADO.NET Entity Framework as follows var result
I have a simple Nhibernate Linq query that is returning more results than expected:
I have a linq query that is querying over IEnumberable. When I have a
Wondering if there is any way to get the lambda expressions that result from
I have a D object created from the automatic mapping of the D table.
I have a table with a 'Wav' column that is of type 'VARBINARY(max)' (storing

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.