使用 LINQ 连接两个表

发布于 2024-10-30 08:22:59 字数 709 浏览 2 评论 0原文

我有两张桌子:

PlanMaster(计划名称、产品 ID)

产品点(Entity_ID、产品_ID、Comm1、Comm2)

现在我将 Entity_ID 存储到一个存储在“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”? '布尔'

这里出了什么问题?感谢您提前提出意见!

I have two tables:

PlanMaster (PlanName, Product_ID)

and

ProductPoints (Entity_ID, Product_ID, Comm1, Comm2)

Now I am storing Entity_ID into a Session which is stored into an 'int':

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

I want to show in my LINQ query all of the items from above tables which has

Entity_ID = getEntity

Here is my LINQ query:

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?' to 'bool'

What is going wrong here? Thank you for your comments in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

戒ㄋ 2024-11-06 08:22:59

尝试将其更改为

 where s.Entity_ID == getEntity

Try changing it to

 where s.Entity_ID == getEntity
飘逸的'云 2024-11-06 08:22:59
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;

= 不等于 ==

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

苯莒 2024-11-06 08:22:59

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

where s.Entity_ID = getEntity should be where s.Entity_ID == getEntity.

红焚 2024-11-06 08:22:59

不应该是双等号吗?

Shouldn't that be a double equals?

眼泪淡了忧伤 2024-11-06 08:22:59
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();
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();
扛起拖把扫天下 2024-11-06 08:22:59

我认为这样就可以了,

其中 s.Entity_ID == getEntity

I think this will do,

where s.Entity_ID == getEntity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文