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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:00:10+00:00 2026-06-11T02:00:10+00:00

I am trying to find a better way to write an effective JOIN using

  • 0

I am trying to find a better way to write an effective JOIN using LINQ and Lambda expressions, hopefully using a Join, to work with the following types:

public class Patent
{
    public string Title { get; set; }
    public string YearOfPublication { get; set; }
    public long[] InventorIds { get; set; }
}

public class Inventor
{
    public long Id { get; set; }
    public string Name { get; set; }
}

The subsequent data is being created as such:

public static class PatentData
{
    public static readonly Inventor[] Inventors = new Inventor[]
    {
        new Inventor(){
            Name="Benjamin Franklin", Id=1 },
        new Inventor(){
            Name="Orville Wright", Id=2},
        new Inventor(){
            Name="Wilbur Wright", Id=3}
    };
    public static readonly Patent[] Patents = new Patent[]
    {
        new Patent(){
            Title="Bifocals", YearOfPublication="1784",
            InventorIds=new long[] {1}},
        new Patent(){
            Title="Flying machine", YearOfPublication="1903",
            InventorIds=new long[] {2,3}}
    };
}

To iterate through all the inventors for a particular patent, I am using the following code below.

IEnumerable<Patent> patents = PatentData.Patents;
IEnumerable<Inventor> inventors = PatentData.Inventors;

foreach(Patent p in patents)
{
    var iall = inventors.Where(i => p.InventorIds.Contains(i.Id));
    foreach (Inventor i in iall)
    {
        Debug.WriteLine(p.Title + ": " + i.Id);
    }
}

Although the code above works fine, I would really like to use a LINQ Join statement. The problem, obviously, is that the LINQ Join statement will grumble about the different types (long and long[]) which are primary and foreign keys respectively.

The code that I would have preferred to use of which I can’t seem to get working, is follows:

Patent [] patents = PatentData.Patents;
Inventor [] inventors = PatentData.Inventors;

var result = patents.Join(inventors, patent => patent.InventorIds, inventor => inventor.Id, (patent, inventor) => new
{
    patent.Title,
    inventor.Name
});

This is failing, quite rightly, with the following error:

error CS0411: The type arguments for method ‘System.Linq.Enumerable.Join(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func, System.Func, System.Func)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

So, my question is:

How can I repair the code that has the error to work with the Join statement when used in conjunction with the two types; Patent and Inventor – without modifying the types at all? Is it even possible?

I appreciate that I can change the types so that they are better structured, but humour me for a moment.

  • 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-11T02:00:12+00:00Added an answer on June 11, 2026 at 2:00 am

    You need a join for each individual patent:

    var query = from patent in patents
                from inventorId in patent.InventorIds
                join inventor in inventors on inventorId equals inventor.Id
                select new { patent.Title, inventor.Name };
    

    Of course, if you could avoid using the Id part of your model and instead associate inventors of a patent directly with Inventor objects, that would be simpler.

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

Sidebar

Related Questions

any better way to write this ? $(this).parent().parent().find( dd ul).toggle(); update.. I am trying
I've been trying to find an easy way to write XML using the XmlReader/XmlWriter.
I'm trying to find a better and faster way to insert pretty massive amount
I'm trying to find a less haphazard way than a write-and-test way to write
I'm trying to find a more or less foolproof way to solve the following
I am trying to find out if there is a better way to do
Trying to find the best way to write this SQL statement. I have a
I'm trying to find a better way to check for file access in a
I have been trying to find out if there is a better way to
I am trying to find a better what to do this. In Spring a

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.