简体   繁体   English

实体框架中的内部联接

[英]Inner join in Entity Framework

I have been having a problem with the following query I constructed it keeps returning null, I am hoping that someone could just point me in the right direction. 我在构建以下查询时一直遇到问题,该查询始终返回null,我希望有人可以将我指向正确的方向。

The query is meant to return a list of branches that offer a particular service based on a service ID that is given. 该查询旨在根据给出的服务ID返回提供特定服务的分支机构列表。 I have a many-to-many relationship between two tables being branches and services. 我在作为分支机构和服务的两个表之间存在多对多关系。

from b in database.branches
join bs in database.branch_services on b.branch_id equals bs.branch_id
where bs.service_id == objID
select b;

您是否尝试过lambda语法?

Here is the valid query, adjust table names to match yours: 这是有效的查询,调整表名称以使其符合您的要求:

database.Services.Where(s => s.ServiceId == 3).First().Branches.ToList(); database.Services.Where(s => s.ServiceId == 3).First()。Branches.ToList();

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

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