Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataClasses1DataContext dm= new  DataClasses1DataContext();

foreach (var cln in SelectedList)
                           {
                               var result = dm.Challan_Totals.Where(x => x.Challan_No == cln)
                                              .Join(dm.Challans, ct => ct.Challan_No, c => c.Challan_No, (ct, c) => new { ct, c })
                                              .Join(dm.Rates, ctc => new
                                              {
                                                  Type = ctc.ct.Type,
                                                  Own_Company = ctc.c.Own_Comany,
                                                  Parti_Name = ctc.c.Parti_Name
                                              },
                                                   rt => new
                                                   {
                                                       Type = rt.Type,
                                                       Own_Company = rt.Own_Comany,
                                                       Parti_Name = rt.Parti_Name
                                                   },
                                                   (ctc, rt) => new { ctc, rt })

                                              .Select(res => new
                                              {
                                                  Challan_no = res.ctc.ct.Challan_No,
                                                  Type = res.ctc.ct.Type,
                                                  Measurment = res.ctc.ct.Measurement,
                                                  Rate1 = res.rt.Rate1,
                                                  Amount = (res.ctc.ct.Measurement) * ((double)res.rt.Rate1)
                                              })
                                              .ToList();}



I get this type Error...

VB
Error   1   The type arguments for method 'System.Linq.Queryable.Join<TOuter,TInner,TKey,TResult>(System.Linq.IQueryable<TOuter>, System.Collections.Generic.IEnumerable<TInner>, System.Linq.Expressions.Expression<System.Func<TOuter,TKey>>, System.Linq.Expressions.Expression<System.Func<TInner,TKey>>, System.Linq.Expressions.Expression<System.Func<TOuter,TInner,TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. G:\$WORKS\Iqbal Silks\Iqbal Silks\Billing_Control\Genbill.xaml.cs   84  48  Iqbal Silks
Posted
Updated 13-Dec-14 18:56pm
v3
Comments
BillWoodruff 13-Dec-14 12:47pm    
You are making a mistake to chain all those complex Linq operations before you have debugged each step of the transformation involved separately, and fully tested it.

In its current state, it will take a genius to figure out what's going on, but we do have some geniuses around here.
mukesh mourya 13-Dec-14 13:06pm    
After carefully examine i Have Solved Its...:)
Maciej Los 13-Dec-14 13:45pm    
Share your solution or delete question ;)

1 solution

The key points when joining on multiple columns are:

The column types must be the same, and
The column names must also be the same.



The above query has been tested and works OK with the following mock-up:

Class mock-up resembling the SQL Schema:

C#
<pre lang="cs">class Challan_Total
{
    public int Id {get; set;}
    public string Challan_No {get; set;}
    public string Type {get; set;}
}

class Challan
{
    public int Id { get; set; }
    public string Challan_No {get; set;}
    public string Own_Comany {get; set;}
    public string Parti_Name {get; set;}
}

class Rate
{
    public string Company_Id {get; set;}
    public string Parti_Id {get; set;}
    public string Meterial_type { get; set;}
    public string Rate1 { get; set; }
}



Sample data:

C#
List<Challan_Total> lstChallanTotal = new List<Challan_Total>()
{
    new Challan_Total { Challan_No = "1", Id = 1, Type = "1"},
    new Challan_Total { Challan_No = "2", Id = 1, Type = "1"},
    new Challan_Total { Challan_No = "3", Id = 2, Type = "2"}
};

List<Challan> lstChallan = new List<Challan>()
{
    new Challan { Id = 1, Challan_No = "1", Own_Comany = "1", Parti_Name = "1"},
    new Challan { Id = 2, Challan_No = "2", Own_Comany = "1", Parti_Name = "2"},
    new Challan { Id = 3, Challan_No = "3", Own_Comany = "3", Parti_Name = "3"}
};

List<Rate> lstRate = new List<Rate>() 
{ 
    new Rate { Company_Id = "1", Parti_Id = "1", Meterial_type = "1", Rate1 = "p1"},
    new Rate { Company_Id = "2", Parti_Id = "1", Meterial_type = "1", Rate1 = "p2" },
    new Rate { Company_Id = "3", Parti_Id = "2", Meterial_type = "2", Rate1 = "p3" }
};
 
Share this answer
 
v2
Comments
BillWoodruff 13-Dec-14 23:49pm    
+4 I'm glad to see you did post your solution ! Of course, looking at your original code, you can't really know what objects like 'dm are, although one could guess it's a result of database query.
mukesh mourya 14-Dec-14 0:59am    
I improved My question over there

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900