我的Linq Lambda表达式中出错,请指导我解决它。 [英] i get error in my Linq Lambda Expression please guide Me to solve it.

查看:114
本文介绍了我的Linq Lambda表达式中出错,请指导我解决它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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...

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

推荐答案

WORKS \Iqbal Silks \Iqbal Silks\Billing_Control\Genbill.xaml.cs 84 48 Iqbal Silks
WORKS\Iqbal Silks\Iqbal Silks\Billing_Control\Genbill.xaml.cs 84 48 Iqbal Silks


加入多列时的关键点是:



列类型必须相同,并且

列名也必须是相同的。






以上查询已经过测试,可以通过以下模拟工作正常:



类似于SQL Schema的类模型:



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:

<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:

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" }
};


这篇关于我的Linq Lambda表达式中出错,请指导我解决它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆