【问题标题】:Joining two tables using LINQ使用 LINQ 连接两个表
【发布时间】:2011-04-06 19:25:59
【问题描述】:

我有两张桌子:

PlanMaster (PlanName, Product_ID)

ProductPoints(Entity_ID、Product_ID、Comm1、Comm2)

现在我将 Entity_ID 存储到一个 Session 中,该 Session 存储在一个“int”中:

int getEntity = Int16.Parse(Session["EntitySelected"].ToString());

我想在我的 LINQ 查询中显示上表中所有具有

的项目

Entity_ID = getEntity

这是我的 LINQ 查询:

var td = from s in cv.Entity_Product_Points join r in dt.PlanMasters on s.Product_ID equals r.Product_ID
         where s.Entity_ID = getEntity
         select s;

现在它给了我一个错误,上面写着:

不能隐式转换类型“int?” '布尔'

这里出了什么问题?提前感谢您的 cmets!

【问题讨论】:

    标签: c# asp.net linq linq-to-sql


    【解决方案1】:

    试试改成

     where s.Entity_ID == getEntity
    

    【讨论】:

      【解决方案2】:
      var td =
          from s in cv.Entity_Product_Points
          join r in dt.PlanMasters on s.Product_ID equals r.Product_ID
          where s.Entity_ID == getEntity
          select s;
      

      = 不等于 ==

      【讨论】:

        【解决方案3】:

        where s.Entity_ID = getEntity 应该是where s.Entity_ID == getEntity

        【讨论】:

          【解决方案4】:

          不应该是双等吗?

          【讨论】:

            【解决方案5】:
            var db1 = (from a in AccYearEntity.OBLHManifests select a).ToList();
            var db2 = (from a in MasterEntity.UserMasters select a).ToList();
            
            var query = (from a in db1
                         join b in db2 on a.EnteredBy equals b.UserId
                         where a.LHManifestNum == LHManifestNum
                         select new { LHManifestId = a.LHManifestId, LHManifestNum = a.LHManifestNum, LHManifestDate = a.LHManifestDate, StnCode = a.StnCode, Operatr = b.UserName }).FirstOrDefault();
            

            【讨论】:

            • 请描述您的解决方案。
            【解决方案6】:

            我认为这样就可以了,

            其中 s.Entity_ID == getEntity

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-01-12
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多