简体   繁体   English

使用LINQ连接两个表

[英]Joining two tables using LINQ

I have two tables: 我有两张桌子:

PlanMaster (PlanName, Product_ID) PlanMaster(PlanName,Product_ID)

and

ProductPoints (Entity_ID, Product_ID, Comm1, Comm2) ProductPoints(Entity_ID,Product_ID,Comm1,Comm2)

Now I am storing Entity_ID into a Session which is stored into an 'int': 现在我将Entity_ID存储到一个存储在'int'中的Session中:

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

I want to show in my LINQ query all of the items from above tables which has 我想在我的LINQ查询中显示上面表格中的所有项目

Entity_ID = getEntity Entity_ID = getEntity

Here is my LINQ query: 这是我的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;

Now its giving me an error which says: 现在它给我一个错误,上面写着:

Cannot implicitly convert type 'int?' 无法隐式转换类型'int?' to 'bool' 'bool'

What is going wrong here? 这里出了什么问题? Thank you for your comments in advance! 感谢您提前的意见!

尝试将其更改为

 where s.Entity_ID == getEntity
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;

= not equal to == =不等于==

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

难道不应该是双等于?

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();

I think this will do, 我想会这样做,

where s.Entity_ID == getEntity 其中s.Entity_ID == getEntity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM