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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:56:57+00:00 2026-06-06T09:56:57+00:00

I am trying to write equivalent linq code for following query. SELECT A.* FROM

  • 0

I am trying to write equivalent linq code for following query.

SELECT A.*  
FROM  
(  
    SELECT * FROM TableA   
    WHERE id = 100  
) a  
JOIN   
(  
    SELECT Name, MAX(AnotherId) AnotherId   
    FROM TableA   
    WHERE id = 100  
    GROUP BY Name   
) b  
on a.Name  = b.Name and a.AnotherId = b.AnotherId   

This is the linq

var Collection = from R in DbContext.TableA  
join G in (DbContext.TableA.Where(r => r.Id == 100).GroupBy(r => new { r.Name, r.AnotherId } ).Select(g => new { Name = g.Name , AnotherId = g.Max(o => o.AnotherId) }))  
on new { R.Name, R.AnotherId } equals new { G.Name, G.AnotherId }  
where R.Id == 100  
select R;  

But I am getting following compilation error that I don’t know how to fix. Any thoughts

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to ‘Join’.

Error 7 ‘System.Linq.IGrouping’ does not contain a definition for ‘Name’ and no extension method ‘Name’ accepting a first argument of type ‘System.Linq.IGrouping’ could be found (are you missing a using directive or an assembly reference?)

  • 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-06T09:56:59+00:00Added an answer on June 6, 2026 at 9:56 am

    You group by r.Name, r.AnotherId, when you just want to group by r.Name.

    var Collection = from R in DbContext.TableA  
    join G in (DbContext.TableA
                          .Where(r => r.Id == 100)
                          .GroupBy(r => r.Name)
                          .Select(g => new { Name = g.Key , AnotherId = g.Max(o => o.AnotherId) }))  
    on new { R.Name, R.AnotherId } equals new { G.Name, G.AnotherId }  
    where R.Id == 100  
    select R; 
    

    And to have all in Fluent Syntax

    var collection = DbContext.TableA
                              .Where(t1 => t1.Id == 100)
                              .Join(DbContext.TableA
                                    .Where(t2 => t2.Id == 100)
                                    .GroupBy(t2 => t2.Name)
                                    .Select(group => new{Name = group.Key, 
                                                          AnotherId = group.Max(e => e.AnotherId)})
                                     ),
                                     t1 => new{t1.Name, t1.AnotherId} ,
                                     t2 => new{t2.Name, t2.AnotherId},
                                     (t1, t2) => t1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write up the LINQ statement that is equivalent to: select e.EmployeeID,
I'm trying to write a LINQ expression that will join two tables and return
I'm currently trying to write a Dump() method from LinqPad equivalent iin C# for
I am trying to write the C# equivalent to the following: typedef struct BATT_ID
I'm trying to write an HQL query to select objects which contain an object
For the asm emulator i'm trying to write to convert ASM code to equivalent
Is it possible to write code like the following. I'm trying to using Moq
I am trying to write a proper Rails abstracted SQL statement equivalent to: SELECT
I'm trying to write the equivalent of strchr, but with NSStrings... I've currently got
I am trying to write a Java equivalent for a function in C#. The

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.