Entity Framework Query for inner join

后端 未结 3 1557
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 19:22

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

3条回答
  •  佛祖请我去吃肉
    2020-12-12 20:15

    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
    

提交回复
热议问题