Donate

The type of one of the expression in the join clause is incorrect.Type inference failed in the call to GroupJoin In C#

Hi,
I just tested on grouping two collections using GroupJoin approach in LINQ to XML. In the example, the two collections are Customers and Companies. In which, companies served as grouping for the customers. In simple terms, identify a customer of which company he or she belongs. The code below produced an error The type of one of the expression in the join clause is incorrect.Type inference failed in the call to GroupJoin.
XElement companiesAndCustomers = new XElement("CompaniesAndCustomers",
   from company in companies
   join customer in customers on 
        company equals customer.CompanyName
        into groupCompany
        select new XElement("Company",
               new XAttribute("CompanyName", company.CompanyName),
               new XAttribute("Country", company.Country),
                   from subCustomer in groupCompany
                        select new XElement("Customer", subCustomer.LastName + ", " + subCustomer.FirstName
                               , new XAttribute("Age",subCustomer.Age))));
As I glanced through the code, I joined an entire company object to a customer CompanyName property. To fix that, I added a CompanyName property to company object that is of exact match with customer's CompanyName type.
XElement companiesAndCustomers = new XElement("CompaniesAndCustomers",
   from company in companies
   join customer in customers on 
        company.CompanyName equals customer.CompanyName
        into groupCompany
        select new XElement("Company",
               new XAttribute("CompanyName", company.CompanyName),
               new XAttribute("Country", company.Country),
                   from subCustomer in groupCompany
                        select new XElement("Customer", subCustomer.LastName + ", " + subCustomer.FirstName
                               , new XAttribute("Age",subCustomer.Age))));
:)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations