实体框架查询的内部连接 [英] Entity Framework Query for inner join

查看:139
本文介绍了实体框架查询的内部连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是查询为:

 选择S *从服务小号
内部联接ServiceAssignment SA在sa.ServiceId = s.Id
,其中sa.LocationId = 1

在实体框架?



这是我写的:

  VAR SERV =(从S IN db.Services 
在s.id位置加入SL等于sl.id
,其中sl.id = s.id
选择S).ToList();



但它是错误的。有人可以指导我的路?


在db.Services $
解决方案

 从s b $ b在db.ServiceAssignments加入SA在s.Id等于sa.ServiceId 
,其中sa.LocationId == 1
选择s

其中,分贝的DbContext 。生成的查询看起来像(样本EF6):

  SELECT [Extent1] [ID] AS [ID] $ B $ 。b  - 从服务表
从[DBO]等领域[服务] AS [Extent1]
INNER JOIN [DBO] [ServiceAssignments] AS [Extent2]
ON [Extent1]。 [ID] = [Extent2]。[服务ID]
WHERE [Extent2]。[LocationId] = 1


What would be the query for:

select s.* from Service s 
inner join ServiceAssignment sa on sa.ServiceId = s.Id
where  sa.LocationId = 1

in entity framework?

This is what I wrote:

 var serv = (from s in db.Services
                join sl in Location on s.id equals sl.id
                where sl.id = s.id
                select s).ToList();

but it's wrong. Can some one guide me to the path?

解决方案

from s in db.Services
join sa in db.ServiceAssignments on s.Id equals sa.ServiceId
where sa.LocationId == 1
select s

Where db is your DbContext. Generated query will look like (sample for EF6):

SELECT [Extent1].[Id] AS [Id]
       -- other fields from Services table
FROM [dbo].[Services] AS [Extent1]
INNER JOIN [dbo].[ServiceAssignments] AS [Extent2]
    ON [Extent1].[Id] = [Extent2].[ServiceId]
WHERE [Extent2].[LocationId] = 1

这篇关于实体框架查询的内部连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆