【问题标题】:Error 25 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'错误 25 连接子句中的表达式之一的类型不正确。调用“加入”时类型推断失败
【发布时间】:2013-01-11 07:51:44
【问题描述】:

我通过在两个表上应用连接从一个表中获取数据,但是我收到了这个错误:

Error   40  The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'.   C:\Documents and Settings\Ashir\My Documents\OpenLearningSolutions08-01-2013\OpenLearningSolutions\purchase.aspx.cs 70  21  C:\...\OpenLearningSolutions\

这是我的代码:

OLSContainer ols = new OLSContainer();
        var reSet = from l in ols.LEVEL_COURSE
                    join lp in ols.PACKAGES 
                    on new { l.course_ID, l.levelID } equals new { lp.course_ID, lp.level_ID }
                    select l;

虽然所有四列都是 int nullabe 类型,但我收到此错误。请帮助我。

【问题讨论】:

    标签: asp.net entity-framework join


    【解决方案1】:

    在您的 LINQ 表达式中,成员的名称不同,因此类型最终不同,因此 C# 无法确定两者之间的共同类型。

    试试这个。

    OLSContainer ols = new OLSContainer();
    var reSet = from l in ols.LEVEL_COURSE
                    join lp in ols.PACKAGES 
                    on new { l.course_ID, l.levelID } equals new { course_ID = lp.course_ID, levelID = lp.level_ID }
                    select l;
    

    【讨论】:

    • 是join表达式左侧的成员名
    【解决方案2】:

    我通过这种方式从表中选择数据解决了我的问题:

    OLSContainer ols = new OLSContainer();
            var reSet = (from l in ols.LEVEL_COURSE
                        from p in ols.PACKAGES
                        where l.course_ID == p.course_ID && l.levelID == p.level_ID &&    l.course_ID==courseID
                        select new { l.levelID, l.levelName }).Distinct();
    

    【讨论】:

      【解决方案3】:

      如果你是在比较 int?和 int 例如,您可以将 .Value 附加到可为空的属性。

      【讨论】:

      • 谢谢,但我自己解决了,也自己给出了答案..:)
      猜你喜欢
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 2012-04-25
      • 1970-01-01
      • 2014-04-14
      相关资源
      最近更新 更多